Kubernetes – How to log into the kubernetes-dashboard with a token

  devops

You’re stuck at this place: 

http://localhost:8001/api/v1/namespaces/kube-system/services/https:kubernetes-dashboard:/proxy/#!/login

Create a service account:

kubectl create serviceaccount cluster-admin-dashboard-sa

kubectl create clusterrolebinding cluster-admin-dashboard-sa \
  --clusterrole=cluster-admin \
  --serviceaccount=default:cluster-admin-dashboard-sa

Get the secret:

kubectl get secret | grep cluster-admin-dashboard-sa

Ex output: 

cluster-admin-dashboard-sa-token-hhxv9   kubernetes.io/service-account-token   3      10m

Copy the token, including the 6 characters after -token (in the above example it’s “cluster-admin-dashboard-sa-token-hhxv9“)

Describe the secret to get the token:

kubectl describe secret cluster-admin-dashboard-sa-token-hhxv9

Example output:

Copy the entire token, in this example from “ey… ” to “…t7g”

Go to the login console:

http://localhost:8001/api/v1/namespaces/kube-system/services/https:kubernetes-dashboard:/proxy/#!/login

Paste the token

You’re in.

Note: as of 11/2019, I can’t log into the dashboard anymore, I have to create an ssh tunnel and use http://localhost:8001/… instead
i.e.
# open git bash locally
ssh -L 8001:localhost:8001 user@kuberneteshost

# go to the dashboard, use localhost:8001 
http://localhost:8001/api/v1/namespaces/kube-system/services/https:kubernetes-dashboard:/proxy/#/login

# select log in with token, and paste the secret token from above