unable to access kubernetes dashboard via token

12,064

Solution 1

Try connect with https, I have same problem, and this works for me

Kubernetes Manual:

NOTE: Dashboard should not be exposed publicly using kubectl proxy command as it only allows HTTP connection. For domains other than localhost and 127.0.0.1 it will not be possible to sign in. Nothing will happen after clicking Sign in button on login page. Logging in is only available when accessing Dashboard over HTTPS or when domain is either localhost or 127.0.0.1. It's done this way for security reasons. Closing as this works as intended.

Solution 2

Try This token (output):

 kubectl -n kube-system get secret |grep  kubernetes-dashboard-token |cut -f1 -d ' ' |  xargs kubectl -n kube-system describe  secret

if doesn't work try/test login with this token (output) :

kubectl -n kube-system get secret |grep  namespace-controller-token  |cut -f1 -d ' ' |  xargs kubectl -n kube-system describe  secret

Good luck..

Solution 3

I faced this problem recently after upgrading k8s version to 1.16. Normally, I was able to access dashboard on local without any login but after that upgrade, it started to open login page first and even though I used a valid token, it didn't let me into dashboard. (There was no response, the page was just stuck)

In order to resolve the issue firstly I removed dashboard related resources.

kubectl delete clusterrolebinding kubernetes-dashboard

Then I deployed the newest dashboard version with the following command.

kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v2.0.0/aio/deploy/recommended.yaml

After the above steps, I run proxy command again and this time, by entering the token, it proceeded with a dashboard page.

Edit: If you get cluster role related error and can't open any actual content, you may need to run the following commands:

kubectl delete clusterrolebinding kubernetes-dashboard
kubectl create clusterrolebinding kubernetes-dashboard --clusterrole=cluster-admin --serviceaccount=kube-system:kubernetes-dashboard --user=clusterUser

Solution 4

You should create an admin user first and add the cluster-admin clusterrolebinding to it:

Use these files admin-user.yaml and admin-user-clusterrolebinding.yaml to create the admin user with the cluster-admin clusterrolebinding:

[root@k8s-1 kubernetes-via-kubeadm]# kubectl create -f admin-user.yaml
serviceaccount "admin-user" created

[root@k8s-1 kubernetes-via-kubeadm]# kubectl create -f admin-user-clusterrolebinding.yaml 
clusterrolebinding "admin-user" created

To get the token for this admin-user:

[root@k8s-1 kubernetes-via-kubeadm]# kubectl -n kube-system describe secret $(kubectl -n kube-system get secret | grep admin-user | awk '{print $1}') | grep ^token: | sed 's/token:[ ]*/Token:\n/'
Token:
eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJrdWJlcm5ldGVzL3NlcnZpY2VhY2NvdW50Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9uYW1lc3BhY2UiOiJrdWJlLXN5c3RlbSIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VjcmV0Lm5hbWUiOiJhZG1pbi11c2VyLXRva2VuLW1oNzIyIiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9zZXJ2aWNlLWFjY291bnQubmFtZSI6ImFkbWluLXVzZXIiLCJrdWJlcm5ldGVzLmlvL3NlcnZpY2VhY2NvdW50L3NlcnZpY2UtYWNjb3VudC51aWQiOiIwNWM0ZDZmZC0yZjYyLTExZTgtYTMxNi1jMDNmZDU2MmJiNzciLCJzdWIiOiJzeXN0ZW06c2VydmljZWFjY291bnQ6a3ViZS1zeXN0ZW06YWRtaW4tdXNlciJ9.butKxegADx3JQvKpn9Prf7RL_SoxaEyi_scYOvXurm4BAwEj8zfC9a7djqQ9mBtd5cQHlljvMb-3qFc6UPOzAwR8fc5khk-nAkH-5XeahpT8WsyxMcKxqLuyAg8gh4ZtMKvBPk9kOWDtyRBzAeGkisbLxr43ecKO71F5G8D7HR2UGSm-x4Pvhq0uqj8GyIcHw902Ti92BPuBRf-SyTl8uDCQJSDkS5Tru5w0p82borNuVXd1mmDwuI87ApQrqXTY9rbJ61m8iTr0kKJBqw5bHAUAhxwAVtVEKQNNKT6cxWp1FlhHbNkM9bhcj1qj8bN1QCMjPWlWKj7NkPbbBAJthQ

You can use the token to login to your kubernetes-dashboard.

Share:
12,064
zhwlx22
Author by

zhwlx22

Updated on June 28, 2022

Comments

  • zhwlx22
    zhwlx22 almost 2 years
    1. I have setup a kubernetes using kubeadm v1.8.5
    2. Setup a dashboard using:
    wget https://raw.githubusercontent.com/kubernetes/dashboard/v1.8.0/src/deploy/recommended/kubernetes-dashboard.yaml`
    
    kubectl create -f kubernetes-dashboard.yaml
    
    kubectl create -f kubernetes-dashboard-admin.rbac.yaml
    
    1. Then setup kubectl proxy, using http://localhost:8001/api/v1/namespaces/kube-system/services/https:kubernetes-dashboard:/proxy/ as recommended.

    2. When I am trying to login using kubernetes-dashboard-admin token. Token was received by using the command:

        kubectl -n kube-system get secret | grep -i dashboard-admin | awk '{print $1}' | xargs -I {} 
        kubectl -n kube-system describe secret {}
    

    Here comes my problem: I CANT access the dashboard via token, when I paste the token and click "Signin" botton, nothing happened. And I get nothing in my log[using tail -f /var/log/messages and journalctl -xeu kubelet]. I am a newbee on k8s, maybe someone could tell me where the log is?
    enter image description here

    Here are my k8s cluster-info:

    [root@k8s-1 pki]# kubectl cluster-info

    Kubernetes master is running at https://172.16.1.15:6443
    KubeDNS is running at https://172.16.1.15:6443/api/v1/namespaces/kube-system/services/kube-dns/proxy
    kubernetes-dashboard is running at https://172.16.1.15:6443/api/v1/namespaces/kube-system/services/kubernetes-dashboard/proxy
    
    To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.
    

    [root@k8s-1 pki]# kubectl get nodes

    NAME      STATUS    ROLES     AGE       VERSION
    k8s-1     Ready     master    4d        v1.8.5
    k8s-2     Ready     <none>    4d        v1.8.5
    k8s-3     Ready     <none>    4d        v1.8.5
    

    [root@k8s-1 pki]# kubectl get pods --all-namespaces

    NAMESPACE     NAME                                    READY     STATUS    RESTARTS   AGE
    kube-system   etcd-k8s-1                              1/1       Running   2          4d
    kube-system   kube-apiserver-k8s-1                    1/1       Running   2          4d
    kube-system   kube-controller-manager-k8s-1           1/1       Running   1          4d
    kube-system   kube-dns-545bc4bfd4-94vxx               3/3       Running   3          4d
    kube-system   kube-flannel-ds-97frd                   1/1       Running   2          4d
    kube-system   kube-flannel-ds-bl9tp                   1/1       Running   2          4d
    kube-system   kube-flannel-ds-bn9hp                   1/1       Running   1          4d
    kube-system   kube-proxy-9ncdm                        1/1       Running   0          4d
    kube-system   kube-proxy-qjm9k                        1/1       Running   1          4d
    kube-system   kube-proxy-rknz4                        1/1       Running   0          4d
    kube-system   kube-scheduler-k8s-1                    1/1       Running   2          4d
    kube-system   kubernetes-dashboard-7486b894c6-tszq9   1/1       Running   0          2h
    

    The kubernetes-dashboard-admin-rbac.yaml is:

    [root@k8s-1 dashboards]# cat kubernetes-dashboard-admin.rbac.yaml

    ---
    apiVersion: v1
    kind: ServiceAccount
    metadata:
      labels:
        k8s-app: kubernetes-dashboard
        kubernetes.io/cluster-service: "true"
        addonmanager.kubernetes.io/mode: Reconcile
      name: kubernetes-dashboard-admin
      namespace: kube-system
    
    ---
    apiVersion: rbac.authorization.k8s.io/v1beta1
    kind: ClusterRoleBinding
    metadata:
      name: kubernetes-dashboard-admin
      annotations:
        rbac.authorization.kubernetes.io/autoupdate: "true"
      labels:
        k8s-app: kubernetes-dashboard
    roleRef:
      apiGroup: rbac.authorization.k8s.io
      kind: ClusterRole
      name: cluster-admin
    subjects:
    - kind: ServiceAccount
      name: kubernetes-dashboard-admin
      namespace: kube-system
    

    Any suggestions? Thank you!!!