File tree 1 file changed +20
-0
lines changed
1 file changed +20
-0
lines changed Original file line number Diff line number Diff line change
1
+ (:ns clj-http.examples.kubernetes-pod
2
+ " This is an example of calling the Kubernetes API from inside a pod. K8s uses a
3
+ custom CA so that you can authenticate the API server, and provides a token per pod
4
+ so that each pod can authenticate itself with the APi server.
5
+
6
+ If you are still having 401/403 errors, look carefully at the message, if it includes
7
+ a ServiceAccount name, this part worked, and your problem is likely at the Role/RoleBinding level."
8
+ (:require [clj-http.client :as http]
9
+ [less.awful.ssl :refer [trust-store]]))
10
+
11
+ ; ; Note that this is not a working example, you'll need to figure out your K8s API path.
12
+ (let [k8s-trust-store (trust-store (clojure.java.io/file " /var/run/secrets/kubernetes.io/serviceaccount/ca.crt" ))
13
+ bearer-token (format " Bearer %s" (slurp " /var/run/secrets/kubernetes.io/serviceaccount/token" ))
14
+ kube-api-host (System/getenv " KUBERNETES_SERVICE_HOST" )
15
+ kube-api-port (System/getenv " KUBERNETES_SERVICE_PORT" )]
16
+ (http/get
17
+ (format " https://%s:%s/apis/<something-protected>" kube-api-host kube-api-port)
18
+ {:trust-store k8s-trust-store
19
+ :headers {:authorization bearer-token}}))
20
+
You can’t perform that action at this time.
0 commit comments