For additional context on RBAC and ServiceAccounts see:
1) How many ServiceAccounts exist in the default namespace?
Run:
default namespace: default and dev.
2) What is the secret token used by the default ServiceAccount?
Describe the default ServiceAccount:
Tokens: in the output. In this environment the Tokens: field shows None, which indicates there is no separate legacy Secret object listed for that ServiceAccount. Modern Kubernetes clusters use projected service account tokens (mounted into pods by the kubelet) instead of Secret-based tokens, so you may see a projected token volume instead of a Secrets entry.
3) Inspect the dashboard Deployment — what image is used?
List deployments and inspect the dashboard deployment:describe output):
web-dashboard Deployment uses the image gcr.io/kodekloud/customimage/my-kubernetes-dashboard.
4) The dashboard UI shows a permission error when trying to list pods
The dashboard UI reports:default ServiceAccount in the default namespace, which lacks permission to list pods.
To confirm which account the pod uses, inspect the Deployment or Pod spec and check serviceAccount / serviceAccountName. The error message system:serviceaccount:default:default makes it clear the application is running as the default ServiceAccount.
5) Inspect the dashboard Pod — where are service account credentials mounted?
Identify the dashboard pod:describe output:
Service Account: default(near the top)- Under Containers → Mounts: a mount like
/var/run/secrets/kubernetes.io/serviceaccount - Under Volumes: a projected volume such as
kube-api-access-xxxxxwith details likeTokenExpirationSeconds,ConfigMapName: kube-root-ca.crt, andDownwardAPI.
/var/run/secrets/kubernetes.io/serviceaccount via a projected volume.
6) Create a new ServiceAccount for the dashboard with the appropriate access
Instead of using the clusterdefault ServiceAccount, create a dedicated ServiceAccount that will be granted the exact permissions the dashboard needs.
Create the ServiceAccount:
/var/rbac/ and define a Role and RoleBinding that grant dashboard-sa permission to read pods:
dashboard-sa.
7) Create a token for dashboard-sa and use it in the UI
To validate the new ServiceAccount’s permissions, generate a token you can paste into the dashboard login:

8) Automate token mounting by updating the Deployment to use dashboard-sa
Manually pasting a token into the UI is useful for testing, but for production you should configure the Deployment so pods run as the dashboard-sa ServiceAccount. When serviceAccountName is set in the pod template, Kubernetes mounts the projected ServiceAccount token into the pod automatically.
Export the current Deployment YAML:
dashboard.yaml and under the pod template set serviceAccountName in the correct location:
serviceAccountName must be nested under spec.template.spec, not at the top-level spec.
Apply the updated manifest:
kubectl create rather than kubectl apply, applying an edited manifest may show a warning — this is expected and safe for this lab.
9) Verify pods now use dashboard-sa and have credentials mounted
Check the updated Deployment and pods:
describe pod output:
Service Account: dashboard-sa- A volume mount at
/var/run/secrets/kubernetes.io/serviceaccount - The dashboard no longer requires manually pasted tokens — the projected token is mounted automatically and the dashboard can query the API according to the RBAC permissions granted to
dashboard-sa.
Using
serviceAccountName in the pod spec mounts the ServiceAccount token automatically into the pod at /var/run/secrets/kubernetes.io/serviceaccount. Ensure the associated Role and RoleBinding grant only the permissions the application needs (principle of least privilege).Summary
- We identified that the dashboard was running with the
defaultServiceAccount and lacked permission to list pods. - We created
dashboard-saand ensured it had a Role and RoleBinding granting pod read permissions. - We validated access by creating a token and logging into the dashboard.
- We updated the Deployment to use
dashboard-sa, so pods automatically receive the projected token and operate with the intended RBAC permissions.