How to log in to the microk8s Kubernetes Dashboard?

John McGehee picture John McGehee · Mar 14, 2019 · Viewed 7.7k times · Source

I enabled the dashboard in microk8s:

microk8s.enable dns dashboard

I found its IP address:

microk8s.kubectl get all --all-namespaces
    ...
kube-system   service/kubernetes-dashboard ClusterIP 10.152.183.212 <none> 443/TCP 24h
    ...

I tried to display it in my browser using the URL https://10.152.183.212. My browser gives the error "Authentication failed. Please try again.":

Kubernetes dashboard 'Authentication failed. Please try again.'

I have also received the similar error, "Not enough data to create auth info structure."

Answer

Rafael Aguilar picture Rafael Aguilar · Jul 31, 2019

To extend @John's answer, sometimes you could be asked with an HTTP Basic Auth Prompt, you can find those credentials also in:

#/var/snap/microk8s/current/credentials/basic_auth.csv

~/:$ sudo cat /var/snap/microk8s/current/credentials/basic_auth.csv

<password>,admin,admin,"system:masters"

The first value (password) is the actual password, the user would be admin.

Later, you could be asked to login by using the secret token. It can be retrieved in this way:

First, let's figure which is the token name (it is randomize) by getting the secret list:

~/:$ kubectl -n kube-system get secret

NAME                               TYPE                                  DATA   AGE
coredns-token-k64mx                kubernetes.io/service-account-token   3      86s
.
.
kubernetes-dashboard-token-wmxh6   kubernetes.io/service-account-token   3      80s

The last token (kubernetes-dashboard-token-wmxh6) is the one we are looking for, let's get the actual value now:

~/:$ kubectl -n kube-system describe secret kubernetes-dashboard-token-wmxh6 

Name:         kubernetes-dashboard-token-wmxh6
Namespace:    kube-system
Labels:       <none>
Annotations:  kubernetes.io/service-account.name: kubernetes-dashboard
              kubernetes.io/service-account.uid: 538fbe6d-ac1e-40e8-91e9-ec0cf4265545

Type:  kubernetes.io/service-account-token

Data
====
ca.crt:     1115 bytes
namespace:  11 bytes
token:      <token-value>

The value of the token field (<token-value>) will be the token to login to the K8s dashboard.

From there, you should be fine.