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.
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 luckyBind 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-adminList the secrets in the namespace and retrieve the token secret:
kubectl get secret -n lucky kubectl describe secret lucky-admin-token-xxxx -n luckyCopy 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-dashboardCopy 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-dashboardRepeat 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.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
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.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
