Kubernetes ServiceAccounts give Pods an identity; set serviceAccountName and control token mounting
Answer: Create a ServiceAccount in the namespace, set spec.serviceAccountName on the Pod, and grant it permissions with RBAC. A service account is a non-human account that provides a distinct identity in a Kubernetes cluster; if you don't assign one, Kubernetes assigns the namespace's default ServiceAccount.
Commands
kubectl get serviceaccounts
kubectl apply -f - <<EOF
apiVersion: v1
kind: ServiceAccount
metadata:
name: build-robot
EOF
kubectl create token build-robot --duration=1h
apiVersion: v1
kind: Pod
metadata:
name: my-pod
spec:
serviceAccountName: build-robot
automountServiceAccountToken: false
Key facts
- Each service account is bound to a Kubernetes namespace, and every namespace gets a
defaultServiceAccount upon creation. If you delete it, the control plane replaces it with a new one. - With RBAC enabled, default service accounts get no permissions other than the default API discovery permissions.
- By default Kubernetes gets a token through the TokenRequest API and mounts it as a projected volume. These tokens have bounded lifetimes and are automatically invalidated when the Pod is deleted.
- Set
automountServiceAccountToken: falseon the ServiceAccount or the Pod to opt out; if both set it, the Pod spec takes precedence. kubectl create tokenprints a token for that ServiceAccount; the actual duration of the issued token might be shorter, or could even be longer.- ServiceAccounts authenticate with signed JSON Web Tokens (JWTs).
- Before 1.22, Kubernetes gave Pods a long-lived, static token as a Secret. Creating a token Secret is still possible, but the TokenRequest subresource is recommended instead.
See also
Claims
- id: C1 claim: A service account provides a distinct identity in a cluster. source: S1 evidence: "provides a distinct identity in a Kubernetes cluster"
- id: C2 claim: Unassigned Pods get the namespace's default ServiceAccount. source: S1 evidence: "Kubernetes assigns the default ServiceAccount for that namespace to the Pod"
- id: C3 claim: The Pod spec takes precedence over the ServiceAccount. source: S2 evidence: "the Pod spec takes precedence"
Sources
- [S1] Service Accounts. Kubernetes docs. https://kubernetes.io/docs/concepts/security/service-accounts/ . License: CC-BY-4.0. Accessed 2026-11-18.
- [S2] Configure Service Accounts for Pods (source page). kubernetes/website (GitHub). https://github.com/kubernetes/website/blob/main/content/en/docs/tasks/configure-pod-container/configure-service-account.md . License: CC-BY-4.0. Accessed 2026-11-18.
License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Kubernetes docs, Service Accounts; kubernetes/website (GitHub), Configure Service Accounts for Pods (source page). CC-BY-4.0 (https://raw.githubusercontent.com/kubernetes/website/main/LICENSE). Copyright The Kubernetes Authors. Text was condensed and changed from the originals.
License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: Kubernetes docs, Service Accounts; kubernetes/website (GitHub), Configure Service Accounts for Pods (source page). CC-BY-4.0 (https://raw.githubusercontent.com/kubernetes/website/main/LICENSE). Copyright The Kubernetes Authors.
Cite this
iinventedlight. 2026. "Kubernetes ServiceAccounts give Pods an identity; set serviceAccountName and control token mounting." iinventedlight Library, iil:note:yqf8xv2s, version of 2026-11-18. https://iinventedlight.com/library/notes/kubernetes-service-accounts/. License: CC-BY-4.0.
@misc{iil_note_yqf8xv2s,
author = {{iinventedlight}},
title = {{Kubernetes ServiceAccounts give Pods an identity; set serviceAccountName and control token mounting}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-18},
url = {https://iinventedlight.com/library/notes/kubernetes-service-accounts/},
note = {Permanent ID iil:note:yqf8xv2s. License: CC-BY-4.0.},
}
Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).
For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/kubernetes-service-accounts.md.