Newsletter
TechAnV Blog
Get updates on security engineering, Rust, eBPF, and DevSecOps. No spam, unsubscribe anytime.
Check your inbox and click the confirmation link to complete your subscription.
kubectl proxy#
Learned about this today as a way of accessing the Kubernetes REST API.
Assuming you have kubectl setup and authorized against a cluster (I’m using DigitalOcean K8S) you can start a localhost proxy for talking to the API server in the cluster like this:
1kubectl proxy --port 9000This starts a proxy running on localhost port 9000 which can be used to make authenticated API calls to the cluster. The authentication wrapper (which I think defaults to client certificates) is added automatically, so you can just hit http://localhost:9000/ using curl.
1curl localhost:90002{3 "paths": [4 "/.well-known/openid-configuration",5 "/api",6 "/api/v1",7 "/apis",8 "/apis/",9 "/apis/admissionregistration.k8s.io",10 "/apis/admissionregistration.k8s.io/v1",11 "/apis/admissionregistration.k8s.io/v1beta1",12 "/apis/apiextensions.k8s.io",13...Absolutely everything in Kubernetes is exposed via the API. Hitting the homepage, as above, shows a list of API paths. Then you can do things like this:
1% # List nodes in the cluster2% curl localhost:9000/api/v1/nodes3{4 "kind": "NodeList",5 "apiVersion": "v1",6 "metadata": {7 "resourceVersion": "18429049"8 },9 "items": [10 {11 "metadata": {12 "name": "..."13
14% # List pods (effectively containers) in the cluster:15% curl localhost:9000/api/v1/pods16{17 "kind": "PodList",18 "apiVersion": "v1",19 "metadata": {20 "resourceVersion": "18429226"21 },22 "items": [23 {24 "metadata": {25 "name": "alpaca-prod",26 "namespace": "default",27 "uid": "50b03bf7-c46d-4ebb-ab93-df089940fa9c",28 "resourceVersion": "1207774",29 "creationTimestamp": "2021-10-31T21:18:08Z",30 "labels": {31
32% # Show Kubernetes version33% curl localhost:9000/version34{35 "major": "1",36 "minor": "21",37 "gitVersion": "v1.21.5",38 "gitCommit": "aea7bbadd2fc0cd689de94a54e5b7b758869d691",39 "gitTreeState": "clean",40 "buildDate": "2021-09-15T21:04:16Z",41 "goVersion": "go1.16.8",42 "compiler": "gc",43 "platform": "linux/amd64"44}