7
  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!!!

naveen kumar
  • 307
  • 2
  • 11
zhwlx22
  • 171
  • 1
  • 1
  • 14

7 Answers7

13

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.

mpromonet
  • 11,326
  • 43
  • 62
  • 91
9

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

EngSabry
  • 121
  • 1
  • 5
3

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.

tedsluis
  • 41
  • 7
  • Close, but the namespace needs to be kubernetes-dashboard instead: https://github.com/kubernetes/dashboard/blob/master/docs/user/access-control/creating-sample-user.md – gvanto Nov 14 '19 at 07:25
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
Utku A.
  • 738
  • 8
  • 8
0

Run below two command :

sym@symserver:~/Downloads$ token=$(microk8s.kubectl -n kube-system get secret | grep default-token | cut -d " " -f1)

sym@symserver:~/Downloads$ microk8s.kubectl -n kube-system describe secret $token

above command will generate token for dashboard access

Mahesh More
  • 151
  • 7
-1

You should be able to access and login into the dashboard from the assigned cluster IP address. To get the cluster IP just execute

kubectl get svc -n kube-system kubernetes-dashboard

and point your browser to this address (https).

Marcus
  • 159
  • 1
  • 1
  • 7
  • At the time of writing it worked well with the latest version. Didn't check since. Details about what you think is wrong with it would have been more helpful than than a downvote. – Marcus Oct 31 '19 at 18:24
-1

From my other answer:

Get the service token

$ kubectl -o json get secret k8s-dashboard-sa-token-XXXXX | jq -r '.data.token' | base64 -d
eyJhbGci    ... sjcuNA8w
tonejito
  • 319
  • 1
  • 2
  • 5