If you’re using a service account to connect to the API server, Dashboard expects the file /var/run/secrets/kubernetes.io/serviceaccount/token
to be present. It provides a secret token that is required to authenticate with the API server.
Verify with the following commands:
- Start a container that contains curl:
kubectl run test --image=tutum/curl -- sleep 10000
- Check that the container is running:
- Check if secret exists:
kubectl exec $POD_NAME ls /var/run/secrets/kubernetes.io/serviceaccount/
- Get the cluster IP:
- Check the base connectivity from the cluster:
kubectl exec $POD_NAME -- curl -k $CLUSTER_IP
- Connect using tokens:
export TOKEN_VALUE=$(kubectl exec $POD_NAME -- cat /var/run/secrets/kubernetes.io/serviceaccount/token)
kubectl exec $POD_NAME -- curl --cacert /var/run/secrets/kubernetes.io/serviceaccount/ca.crt -H "Authorization: Bearer $TOKEN_VALUE" $CLUSTER_IP
If it isn’t working, there are two possible reasons:
-
The contents of the tokens are invalid.
Find the secret name:
kubectl get secrets --field-selector=type=kubernetes.io/service-account-token
Delete the secret:
kubectl delete secret $SECRET_NAME
It will automatically be recreated.
-
You have a non-standard Kubernetes installation and the file containing the token may not be present.
The API server will mount a volume containing this file, but only if the API server is configured to use the ServiceAccount admission controller. If you experience this error, verify that your API server is using the ServiceAccount admission controller. If you are configuring the API server by hand, you can set this with the --admission-control
parameter. You should use other admission controllers as well. Before configuring this option, read about admission controllers.
For more information, see the following: