---
source: https://iinventedlight.com/library/notes/kubernetes-service-accounts.md
title: "Kubernetes ServiceAccounts give Pods an identity; set serviceAccountName and control token mounting"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "CC-BY-4.0 (Kubernetes docs); CC-BY-4.0 (kubernetes/website (GitHub)); prose restates cited source lines in own words"
license_family: mixed-green
attribution: "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."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-18
status: published
approved_by: "Cole Withington, 2026-11-20 13:14 PT: \"Publish the full batch and rewrite the 6 live notes\""
checked_on: 2026-11-18
as_of: 2026-11-18
confidence: medium
untested: "Not reproduced (2026-11-18). Official docs and source files were read; no test suite, server, or API call was run for this note."
category: coding-references
topic_area: "code-devops: kubernetes service accounts"
tags: [kubernetes, serviceaccount, rbac, tokens, security, identity]
client: Librarian
sources:
  - id: S1
    title: "Service Accounts"
    publisher: Kubernetes docs
    url: https://kubernetes.io/docs/concepts/security/service-accounts/
    accessed: 2026-11-18
    license: "CC-BY-4.0"
  - id: S2
    title: "Configure Service Accounts for Pods (source page)"
    publisher: kubernetes/website (GitHub)
    url: https://github.com/kubernetes/website/blob/main/content/en/docs/tasks/configure-pod-container/configure-service-account.md
    accessed: 2026-11-18
    license: "CC-BY-4.0"
---
# 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

```shell
kubectl get serviceaccounts
kubectl apply -f - <<EOF
apiVersion: v1
kind: ServiceAccount
metadata:
  name: build-robot
EOF
kubectl create token build-robot --duration=1h
```

```yaml
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 `default` ServiceAccount 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: false` on the ServiceAccount or the Pod to opt out; if both set it, the Pod spec takes precedence.
- `kubectl create token` prints 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

- [kubernetes-rbac](https://iinventedlight.com/library/notes/kubernetes-rbac/)
- [kubernetes-secrets](https://iinventedlight.com/library/notes/kubernetes-secrets/)
- [kubernetes-namespaces](https://iinventedlight.com/library/notes/kubernetes-namespaces/)

## 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.

---

Agents: [/agents.md](/agents.md) | [/.well-known/agent-library.json](/.well-known/agent-library.json).
