Skip to content

Instantly share code, notes, and snippets.

@ganeshmaharaj
Last active June 15, 2021 20:59
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ganeshmaharaj/200a32c9522e8b32a3b667cecb17043d to your computer and use it in GitHub Desktop.
Save ganeshmaharaj/200a32c9522e8b32a3b667cecb17043d to your computer and use it in GitHub Desktop.
Access Kube API with curl

Resources

Main Stuff

There are two ways you can talk to the KUBE API.

Kube-proxy

Start a kube proxy server which will act as a reverse proxy for the client.

kubectl proxy --port <PORT_NUMBER> &
curl -s http://localhost:<PORT_NUMBER>/
curl -s http://localhost:<PORT_NUMBER>/api/v1/nodes | jq '.items[].metadata.labels'

Direct KUBE API (Unable to get privileged information)

Get token and URL from cluster and directly talk to Kube API.

Note: Unless you figure out a way to get the call to use root certificates from the system, you will not be able to access privileged data. Best to stick to option #1.

APISERVER=$(kubectl config view | grep server | cut -f 2- -d ":" | tr -d " ")
TOKEN=$(kubectl describe secret $(kubectl get secrets | grep default | cut -f1 -d ' ') | grep -E '^token' | cut -f2 -d':' | tr -d '\t')
curl $APISERVER/api --header "Authorization: Bearer $TOKEN" --insecure
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment