- User accounts — for humans (cluster operators, developers).
- Service accounts — for software (controllers, monitoring, CI/CD).

Example scenario: my-kubernetes-dashboard
Suppose you build a small Python app calledmy-kubernetes-dashboard that queries the Kubernetes API to list Pods and display them in a UI. If the app runs in-cluster it should use a ServiceAccount to authenticate.
- A ServiceAccount is an identity object in a namespace.
- A ServiceAccount has an associated token which the app presents as a Bearer token when calling the API.
- Think of the ServiceAccount as an ID card and the token as the barcode scanned to verify that ID.

Default ServiceAccount and token mounting
Kubernetes automatically creates adefault ServiceAccount in every namespace. When you create a Pod and do not specify a ServiceAccount, the Pod gets the default ServiceAccount.
Kubernetes mounts the ServiceAccount token into the Pod at:
/var/run/secrets/kubernetes.io/serviceaccount
This is provided as a projected volume; the application can read the token file and use it to authenticate.
Example: list ServiceAccounts in the current namespace:
Creating a custom ServiceAccount
Thedefault ServiceAccount has minimal privileges. For more controlled access, create a custom ServiceAccount and bind RBAC roles to it.
Imperative creation:
Attach a ServiceAccount to a Pod
To use a specific ServiceAccount, setserviceAccountName in the Pod spec:
Pod manifest snippet:
automountServiceAccountToken
By default, Kubernetes automatically creates and mounts tokens for ServiceAccounts and Pods. You can disable automatic token creation/mounting at either the ServiceAccount or Pod level.- Disable at the ServiceAccount:
- Or disable on an individual Pod:
automountServiceAccountToken is false for the Pod (or for the associated ServiceAccount and not overridden), the token file will not be mounted into the Pod.
Using ServiceAccount tokens outside the cluster
Sometimes you need a ServiceAccount token for external tools (dashboards, CI/CD, monitoring). Usekubectl create token to generate a token for a ServiceAccount and print it to the console. By default tokens are short-lived (commonly 1 hour). Use --duration to request a longer token.
Create a token:
Summary
- ServiceAccounts are Kubernetes identities used by workloads to talk to the API server.
- Tokens are associated with ServiceAccounts and presented as Bearer tokens.
- Create ServiceAccounts imperatively (
kubectl create serviceaccount) or declaratively with YAML. - Attach a ServiceAccount to a Pod using the
serviceAccountNamefield. - Tokens are mounted into Pods at
/var/run/secrets/kubernetes.io/serviceaccountby default; disable auto-mounting withautomountServiceAccountToken: false. - For external tools (dashboards, CI/CD) use
kubectl create tokento generate a short-lived token; extend duration with--durationas needed. - Always follow least privilege: grant only the RBAC permissions necessary for the ServiceAccount.
By default, tokens created or auto-mounted are short-lived (often 1 hour). Use
kubectl create token --duration=<value> to request a longer-lived token when needed. Always follow least-privilege practices and bind only the necessary RBAC roles to ServiceAccounts.