← All notes

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

See also

Claims

Sources

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

Permanent ID: iil:note:yqf8xv2s

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.},
}

Markdown

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.