K8s Dashboard not logging in (k8s version 1.11)

7/9/2018

I did K8s(1.11) cluster using kubeadm tool. It 1 master and one node in the cluster.

  1. I applied dashboard UI there. kubectl create -f https://raw.githubusercontent.com/kubernetes/dashboard/master/src/deploy/recommended/kubernetes-dashboard.yaml

  2. Created service account (followed this link: https://github.com/kubernetes/dashboard/wiki/Creating-sample-user)

apiVersion: v1
    kind: ServiceAccount
    metadata:
      name: admin-user
      namespace: kube-system

and

apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRoleBinding
metadata:
  name: admin-user
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: cluster-admin
subjects:
- kind: ServiceAccount
  name: admin-user
  namespace: kube-system

Start kube proxy: kubectl proxy --address 0.0.0.0 --accept-hosts '.*'

And access dashboard from remote host using this URL: http://<k8s master node IP>:8001/api/v1/namespaces/kube-system/services/https:kubernetes-dashboard:/proxy/#!/login

Its asking for token for login: got token using this command: kubectl -n kube-system describe secret $(kubectl -n kube-system get secret | grep admin-user | awk '{print $1}')

After copy and apply the token in browser.. its not logging in. Its not showing authentication error too… Not sure wht is wrong with this? Is my token wrong or my kube proxy command wrong?

-- Tushar De
kubeadm
kubectl
kubernetes

1 Answer

7/10/2018

I recreated all the steps in accordance to what you've posted.

Turns out the issue is in the <k8s master node IP>, you should use localhost in this case. So to access the proper dashboard, you have to use:

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

When you start kubectl proxy - you create a tunnel to your apiserver on the master node. By default, Dashboard is starting with ServiceType: ClusterIP. The Port on the master node in this mode is not open, and that is the reason you can't reach it on the 'master node IP'. If you would like to use master node IP, you have to change the ServiceType to NodePort.

You have to delete the old service and update the config by changing service type to NodePort as in the example below (note that ClusterIP is not there because it is assumed by default).

Create a new yaml file name newservice.yaml

---
# ------------------- Dashboard Service ------------------- #

kind: Service
apiVersion: v1
metadata:
  labels:
    k8s-app: kubernetes-dashboard
  name: kubernetes-dashboard
  namespace: kube-system
spec:
  type: NodePort
  ports:
    - port: 443
      targetPort: 8443
  selector:
    k8s-app: kubernetes-dashboard

Delete the old service

 kubectl delete service kubernetes-dashboard -n kube-system

Apply the new service

kubectl apply -f newservice.yaml

Run describe service

kubectl describe svc kubernetes-dashboard -n kube-system | grep "NodePort"

and you can use that port with the IP address of the master node

Type:                   NodePort
NodePort:           <unset> 30518/TCP

http://<k8s master node IP>:30518/api/v1/namespaces/kube-system/services/https:kubernetes-dashboard:/proxy/#!/login

Note that the port number is generated randomly and yours will be probably different.

-- aurelius
Source: StackOverflow