This is from the
Kubernetes In Action book.
You need to take care of authentication. The API server itself says you’re not authorized to access it, because it doesn’t know who you are.
To authenticate, you need an authentication token. Luckily, the token is provided through the default-token Secret mentioned previously, and is stored in the token file in the secret volume.
You’re going to use the token to access the API server. First, load the token into an environment variable:
root@myhome:/# TOKEN=$(cat /var/run/secrets/kubernetes.io/serviceaccount/token)
The token is now stored in the TOKEN environment variable. You can use it when sending requests to the API server:
root@curl:/# curl -H "Authorization: Bearer $TOKEN" https://$KUBERNETES_SERVICE_HOST:$KUBERNETES_PORT_443_TCP_PORT/api/v1/namespaces/default/pods/$HOSTNAME
{ "paths":
[
"/api",
"/api/v1",
"/apis",
"/apis/apps",
"/apis/apps/v1beta1",
"/apis/authorization.k8s.io",
...
"/ui/",
"/version"
]
}
$KUBERNETES_SERVICE_HOST
and$KUBERNETES_PORT_443_TCP_PORT
variables come from? – ruediste