Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to log in to the microk8s Kubernetes Dashboard?

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."

like image 783
John McGehee Avatar asked Mar 14 '19 02:03

John McGehee


People also ask

How do I access the Dashboard on microk8s?

On MacOS and Windows You can then access the Dashboard at https://$CONTAINER_IP:10443 .

How do I open Kubernetes Dashboard?

To access the dashboard endpoint, open the following link with a web browser: http://localhost:8001/api/v1/namespaces/kubernetes-dashboard/services/https:kubernetes-dashboard:/proxy/#!/login . Choose Token, paste the authentication-token output from the previous command into the Token field, and choose SIGN IN.

How do I access Kubernetes Dashboard externally?

Ans: In a terminal window, enter kubectl proxy to make the Kubernetes Dashboard available. Open a browser and go to http://localhost:8001/api/v1/namespaces/kube-system/services/https:kubernetes–dashboard:/proxy/#!/login to display the Kubernetes Dashboard that was deployed when the cluster was created.

Can I use kubectl with microk8s?

At this points, you can already use microk8s if you have kubectl installed.


2 Answers

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.

like image 164
Rafael Aguilar Avatar answered Oct 01 '22 01:10

Rafael Aguilar


kubectl describe service/kubernetes-dashboard -n kube-system

Will return an endpoint. For me it looks like this: 10.1.43.61:8443 Then you can open your browser at https://10.1.43.61:8443 and you probably have to bypass a security warning.

Now you need to authenticate to access the dashboard.

token=$(microk8s kubectl -n kube-system get secret | grep default-token | cut -d " " -f1)
microk8s kubectl -n kube-system describe secret $token

(this command from the docs) Will return the auth token. Paste the token into the login screen and now you should be able to access the dashboard.

like image 32
Flo Avatar answered Oct 01 '22 01:10

Flo