Skip to main content
In this lab we inspect ServiceAccounts, examine the tokens mounted into Pods, and configure a Deployment so its Pods run with the correct ServiceAccount. This ensures an application (like a web dashboard) can authenticate to the Kubernetes API with the intended RBAC permissions.

1) How many ServiceAccounts exist in the default namespace?

Run:
Example output:
In this cluster there are two ServiceAccounts in the default namespace: default and dev.

2) What Secret token is used by the default ServiceAccount?

Describe the default ServiceAccount:
Look for the Tokens section. In this environment the default ServiceAccount shows:
So the default ServiceAccount currently has no token listed (or none is shown).

3) Inspect the dashboard Deployment — what image does it use?

List Deployments and describe the web-dashboard Deployment:
From the Deployment’s Pod template under Containers, the image is:
This is the container image used by the web-dashboard deployment.

4) When accessing the dashboard UI, an error appears: what does it mean?

When trying to list Pods from the dashboard UI, you may see an error like:
This means the application is authenticating to the API as the default ServiceAccount (system:serviceaccount:default:default) and that ServiceAccount does not have RBAC permission to list Pods in the default namespace. In short: the dashboard is running under a ServiceAccount with insufficient privileges.

5) Which ServiceAccount is mounted to the dashboard Pod, and where are its credentials located?

Get the Pod name and describe it:
In the Pod description, check the Service Account field and the Mounts section. Example relevant parts:
So:
  • The Pod is using the default ServiceAccount.
  • The ServiceAccount credentials (token, CA certificate, and namespace file) are projected into the Pod at /var/run/secrets/kubernetes.io/serviceaccount.
Also in the Volumes section you will often see the projected token details such as:
This shows Kubernetes automatically projects the token and related metadata into the Pod.

6) Create a new ServiceAccount for the dashboard: dashboard-sa

Create the ServiceAccount:
Expected output:
If the environment includes RBAC manifests, you may find role and rolebinding YAML files in a directory like /var/rbac/:
Example:
Create a token for the new ServiceAccount (useful for testing by pasting into the dashboard UI):
Example output (token truncated for brevity):
Service account tokens are sensitive credentials. Do not share them, and never commit them into source control.
After pasting this token into the dashboard UI and reloading, the dashboard should be able to list Pods—provided the dashboard-sa has the correct RBAC Role or RoleBinding applied in the environment.
Grant only the minimum permissions required to ServiceAccounts. Avoid binding overly broad roles such as cluster-admin unless absolutely necessary.

7) Configure the web-dashboard Deployment to use dashboard-sa automatically

Instead of manually pasting a token into the UI, update the Deployment so Pods automatically receive the dashboard-sa token. Add serviceAccountName: dashboard-sa under spec.template.spec in the Deployment manifest.
  1. Export the existing Deployment to YAML:
  1. Edit dashboard.yaml. Under spec.template.spec add the serviceAccountName field. Example snippet showing where to add it:
  1. Apply the updated Deployment:
You may see a warning if the Deployment was originally created by a different method, but the update will still be applied. Verify the Deployment status:
Example:
When the new Pod is running, refresh the dashboard UI. Because the Pod now mounts the dashboard-sa token automatically at /var/run/secrets/kubernetes.io/serviceaccount, the dashboard will authenticate as system:serviceaccount:default:dashboard-sa and should be able to list Pods if RBAC permits.

Quick reference — common commands


Summary
  • The dashboard was running with the default ServiceAccount, which lacked permission to list Pods.
  • You created dashboard-sa, generated a token to test permissions, and then updated the Deployment to use serviceAccountName: dashboard-sa. Future Pods will automatically mount the correct token and use the intended RBAC identity.
Links and references

Watch Video