Cloud Native 6 min read

How to Create Kubernetes Dashboard Tokens for Namespace‑Specific and Cluster‑Wide Access

This guide shows step‑by‑step how to generate service‑account tokens in Kubernetes to log into the dashboard with permissions limited to a single namespace, all namespaces, or full cluster‑admin rights, including the required kubectl commands and token extraction details.

Full-Stack DevOps & Kubernetes
Full-Stack DevOps & Kubernetes
Full-Stack DevOps & Kubernetes
How to Create Kubernetes Dashboard Tokens for Namespace‑Specific and Cluster‑Wide Access

Creating a token that can only manage a specific namespace

All commands are executed on the Kubernetes master node.

Create a lucky namespace and a service account lucky-admin in it:

kubectl create namespace lucky
kubectl create serviceaccount lucky-admin -n lucky

Bind the service account to the cluster-admin role (limited to the lucky namespace):

kubectl create rolebinding lucky-admin -n lucky --clusterrole=cluster-admin --serviceaccount=lucky:lucky-admin

List the secrets in the namespace and retrieve the token secret:

kubectl get secret -n lucky
kubectl describe secret lucky-admin-token-xxxx -n lucky

Copy the token value (the long JWT string) and paste it into the dashboard’s token authentication field; the UI will only show resources in the lucky namespace.

Creating a token that can manage all namespaces

List secrets in the kubernetes-dashboard namespace: kubectl get secret -n kubernetes-dashboard Identify the secret named kubernetes-dashboard-token-* and describe it to obtain the token:

kubectl describe secret kubernetes-dashboard-token-ngcmg -n kubernetes-dashboard

Copy the displayed token and use it to log into the dashboard; you will see all namespaces.

Creating an administrator token with full cluster permissions

kubectl create clusterrolebinding dashboard-cluster-admin --clusterrole=cluster-admin --serviceaccount=kubernetes-dashboard:kubernetes-dashboard

Repeat the secret‑listing steps for the kubernetes-dashboard namespace, retrieve the new token, and log in; the dashboard will now display and allow operations on resources across any namespace.

Images in the original article illustrate the login screens before and after applying each token.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

KubernetesRBACServiceAccountClusterRoleBinding
Full-Stack DevOps & Kubernetes
Written by

Full-Stack DevOps & Kubernetes

Focused on sharing DevOps, Kubernetes, Linux, Docker, Istio, microservices, Spring Cloud, Python, Go, databases, Nginx, Tomcat, cloud computing, and related technologies.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.