Install Kubernetes Dashboard

Lars J├Ânsson 2022-12-05

Instructions of how to install the Dashboard on a running Kubernetes cluster. It is based on the recommended setup in the Kubernetes Dashboard README file.



Create private key and certificate that can be used when accessing the Dashboard. It is assumed that they are available at $HOME/certs and named dashboard.key resp. dashboard.crt.

More information about how to create the certificate is described here.

YAML definition

For Dashboard to pickup the certificates, you must pass arguments --tls-cert-file=/dashboard.crt and --tls-key-file=/dashboard.key to the container. First download the file.


Under Deployment section, add arguments to pod definition, it should look as follows:

    - --tls-cert-file=/dashboard.crt
    - --tls-key-file=/dashboard.key
    - --auto-generate-certificates

--auto-generate-certificates can be left in place, and will be used as a fallback.


Create the namespace for the Dashboard and install the secret (key and certificate):

kubectl create namespace kubernetes-dashboard
kubectl create secret generic kubernetes-dashboard-certs --from-file=$HOME/certs -n kubernetes-dashboard

Install the Dashboard:

kubectl apply -f recommended.yaml 

The Dashboard is available as a NodePort. This way of accessing Dashboard is only recommended for development environments in a single node setup.

Edit kubernetes-dashboard service:

kubectl -n kubernetes-dashboard edit service kubernetes-dashboard

You should see yaml representation of the service. Change type: ClusterIP to type: NodePort and save file.

  sessionAffinity: None
  type: NodePort

Next we need to check port on which Dashboard was exposed.

kubectl -n kubernetes-dashboard get service kubernetes-dashboard
NAME                   TYPE       CLUSTER-IP      EXTERNAL-IP   PORT(S)         AGE
kubernetes-dashboard   NodePort   <none>        443:31262/TCP   4m3s

Dashboard has been exposed on port 31262 (HTTPS). Now you can access it from your browser at: https://<master-ip>:31262. master-ip can be found by executing kubectl cluster-info.

Dashboard user

An admin user is needed when accessing the Dashboard. It is created using the Service Account mechanism of Kubernetes and granting this user admin permissions. A bearer token tied to the user is used for login to the Dashboard.

IMPORTANT Make sure that you know what you are doing before proceeding. Granting admin privileges to Dashboard's Service Account might be a security risk.

Creating the user

Create a dashboard-adminuser.yaml file with the following content:

# Admin user for the Dashboard

apiVersion: v1
kind: ServiceAccount
  name: admin-user
  namespace: kubernetes-dashboard


kind: ClusterRoleBinding
  name: admin-user
  kind: ClusterRole
  name: cluster-admin
- kind: ServiceAccount
  name: admin-user
  namespace: kubernetes-dashboard

Create the admin user:

kubectl apply -f dashboard-adminuser.yaml

Getting the bearer token

Now we need to find the token we can use to log in. Execute the following command:

kubectl -n kubernetes-dashboard create token admin-user

It should print something like:


The token can be copied and pasted into Enter token field on the login screen. The default lifetime of the token is 1 hour. It can be changed by using the --duration option. The maximum value is 48 hours.

Create a long-lived API token

NOTE This should only be used in a controlled lab environment

Somtimes it is preferred to use long-lived tokens for Dashboard access. To obtain an API token for the admin-user service account, you create a new secret with a special annotation,

Create a dashboard-token.yaml file with the following content:

apiVersion: v1
kind: Secret
  name: admin-user-secret
  namespace: kubernetes-dashboard
  annotations: admin-user

Create the token:

kubectl apply -f dashboard-token.yaml

View the token by using:

kubectl describe -n kubernetes-dashboard secrets admin-user-secret

The output is similar to this:

Name:         admin-user-secret
Namespace:    kubernetes-dashboard
Labels:       <none>
Annotations: admin-user


ca.crt:     1099 bytes
namespace:  20 bytes
token:      ...

The token can be copied and pasted into Enter token field on the login screen.

NOTE The content of token is elided here.

When you delete a service account that has an associated secret, the Kubernetes control plane automatically cleans up the long-lived token from that secret.