Post

ServiceAccount token from inside of pod

How to use the mounted ServiceAccount token from inside a Kubernetes pod to authenticate against the Kubernetes API.

Every pod in Kubernetes automatically gets a ServiceAccount token mounted at /run/secrets/kubernetes.io/serviceaccount/token. You can use this token to authenticate API requests from inside the pod. The following curl command calls the Kubernetes API using the bearer token.

1
curl https://kubernetes -k -H "Authorization: Bearer $(cat /run/secrets/kubernetes.io/serviceaccount/token)"
This post is licensed under CC BY 4.0 by the author.