How to access the Kubernetes api from within a pod container


I used to be able to curl


as my base URL, but in kubernetes 0.18.0 it gives me "unauthorized". The strange thing is that if I used the external IP address of the API machine (, it works just fine.

Best Solution

In the official documentation I found this:

Apparently I was missing a security token that I didn't need in a previous version of Kubernetes. From that, I devised what I think is a simpler solution than running a proxy or installing golang on my container. See this example that gets the information, from the api, for the current container:

KUBE_TOKEN=$(cat /var/run/secrets/
curl -sSk -H "Authorization: Bearer $KUBE_TOKEN" \

I also use include a simple binary, jq (, to parse the json for use in bash scripts.

Related Question