How to access Kubernetes Dashboard from outside cluster

Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
Subscribe
"The best Linux newsletter on the web"

Kubernetes dashboard is a service running on master node which provide dashboard features to deploy application and services in kubernetes cluster using GUI dashboard, by default it is having “CluterIP” service type. 

You can easily access Kubernetes dashboard within cluster with service type “ClusterIP” but this dashboard will not be accessible outside cluster.

To make dashboard accessible externally, we have to edit kubernetes-dashboard service file with below command.

# kubectl -n kube-system edit service kubernetes-dashboard

# Please edit the object below. Lines beginning with a '#' will be ignored,
# and an empty file will abort the edit. If an error occurs while saving this file will be
# reopened with the relevant failures.
#
apiVersion: v1
kind: Service
metadata:
  annotations:
    kubectl.kubernetes.io/last-applied-configuration: |
      {"apiVersion":"v1","kind":"Service","metadata":{"annotations":{},"labels":{"k8s-app":"kubernetes-dashboard"},"name":"kubernetes-dashboard","namespace":"kube-system"},"spec":{"ports":[{"port":443,"targetPort":8443}],"selector":{"k8s-app":"kubernetes-dashboard"}}}
  creationTimestamp: "2019-11-20T19:46:51Z"
  labels:
    k8s-app: kubernetes-dashboard
  name: kubernetes-dashboard
  namespace: kube-system
  resourceVersion: "13744048"
  selfLink: /api/v1/namespaces/kube-system/services/kubernetes-dashboard
  uid: 7a6ef000-c1f3-4d0d-b543-de16a5c47111
spec:
  clusterIP: X.X.X.X
  externalTrafficPolicy: Cluster
  ports:
  - nodePort: 31630
    port: 443
    protocol: TCP
    targetPort: 8443
  selector:
    k8s-app: kubernetes-dashboard
  sessionAffinity: None
  type: NodePort                 ### Change clusterIP to NodePortstatus:
  loadBalancer: {}

After editing you should be able to see the mapped Clusster IP and Type as NodePort to the kubernetes dashboard

# lsof -i tcp:32414

COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME

kube-prox 3440 root 7u IPv6 32584 0t0 TCP *:32315 (LISTEN)

Now, dashboard will be accessed using https://master-node-ip:port and provide token to sign-in to dashboard

If everything is running correctly, you should see the dashboard login window.

Select the token authentication method and copy your admin token into the field below. Then click the Sign in button.

To get the token to login into Kubernetes dashboard, please use below commands

$ kubectl -n kube-system get secret
# All secrets with type 'kubernetes.io/service-account-token' will allow to log in.
# Note that they have different privileges.
NAME                                     TYPE                                  DATA      AGE
deployment-controller-token-frsqj        kubernetes.io/service-account-token   3         22h

$ kubectl -n kube-system describe secret deployment-controller-token-frsqj
Name:         deployment-controller-token-frsqj
Namespace:    kube-system
Labels:       <none>
Annotations:  kubernetes.io/service-account.name=deployment-controller
              kubernetes.io/service-account.uid=64735958-ae9f-11e7-90d5-02420ac00002

Type:  kubernetes.io/service-account-token

Data
====
ca.crt:     1025 bytes
namespace:  11 bytes
token:      eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJrdWJlcm5ldGVzL3NlcnZpY2VhY2NvdW50Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9uYW1lc3BhY2UiOiJrdWJlLXN5c3RlbSIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VjcmV0Lm5hbWUiOiJkZXBsb3ltZW50LWNvbnRyb2xsZXItdG9rZW4tZnJzcWoiLCJrdWJlcm5ldGVzLmlvL3NlcnZpY2VhY2NvdW50L3NlcnZpY2UtYWNjb3VudC5uYW1lIjoiZGVwbG95bWVudC1jb250cm9sbGVyIiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9zZXJ2aWNlLWFjY291bnQudWlkIjoiNjQ3MzU5NTgtYWU5Zi0xMWU3LTkwZDUtMDI0MjBhYzAwMDAyIiwic3ViIjoic3lzdGVtOnNlcnZpY2VhY2NvdW50Omt1YmUtc3lzdGVtOmRlcGxveW1lbnQtY29udHJvbGxlciJ9.OqFc4CE1Kh6T3BTCR4XxDZR8gaF1MvH4M3ZHZeCGfO-sw-D0gp826vGPHr_0M66SkGaOmlsVHmP7zmTi-SJ3NCdVO5viHaVUwPJ62hx88_JPmSfD0KJJh6G5QokKfiO0WlGN7L1GgiZj18zgXVYaJShlBSz5qGRuGf0s1jy9KOBt9slAN5xQ9_b88amym2GIXoFyBsqymt5H-iMQaGP35tbRpewKKtly9LzIdrO23bDiZ1voc5QZeAZIWrizzjPY5HPM1qOqacaY9DcGc7akh98eBJG_4vZqH2gKy76fMf0yInFTeNKr45_6fWt8gRM77DQmPwb3hbrjWXe1VvXX_g

You will then be greeted by the overview of your Kubernetes cluster.

Other Related Topics

Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
Subscribe
"The best Linux newsletter on the web"
Mel
Melhttps://unixcop.com
Unix/Linux Guru and FOSS supporter

1 COMMENT

  1. It works well from the browser on the same machine as the cluster is installed, but from other workstations dashboard doesn’t work, there are a lot of error in notifications:
    statefulsets.apps is forbidden: User “system:anonymous” cannot list resource “statefulsets” in API group “apps” in the namespace “default”

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest articles

Join us on Facebook