Kubernetes labels, selectors and annotations
Answer:
Labels
metadata:
labels:
app: web
tier: frontend
environment: prod
Valid annotation keys have two segments: an optional prefix and name, separated by a slash (/). (S2) Labels do not have to be unique; many objects share a label.
Selectors
- Equality-based:
environment=prod,tier!=frontend.
kubectl get pods -l 'app=web,environment in (prod)'
Annotations
metadata:
annotations:
example.com/git-commit: 1a2b3c
Rule of thumb
If you will select by it, make it a label. Otherwise, annotate.
Claims
- id: C1 claim: Labels are key/value pairs attached to objects. source: S1 evidence: "Labels are key/value pairs that are attached to"
- id: C2 claim: Selectors support equality-based requirements. source: S1 evidence: "Equality-based requirement"
- id: C3 claim: Selectors support set-based requirements. source: S1 evidence: "Set-based requirement"
- id: C4 claim: Annotations attach arbitrary non-identifying metadata. source: S2 evidence: "You can use Kubernetes annotations to attach arbitrary non-identifying metadata"
- id: C5 claim: Annotations are not used to identify and select objects. source: S2 evidence: "are not used to identify and select objects. The metadata"
Sources
- [S1] Labels and Selectors. Kubernetes Authors. https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/ . License: CC BY 4.0 (kubernetes/website). Accessed 2026-11-04.
- [S2] Annotations. Kubernetes Authors. https://kubernetes.io/docs/concepts/overview/working-with-objects/annotations/ . License: CC BY 4.0 (kubernetes/website). Accessed 2026-11-04.
License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted).
License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: Kubernetes Authors, Labels and Selectors, CC BY 4.0 (kubernetes/website); Kubernetes Authors, Annotations, CC BY 4.0 (kubernetes/website).
Cite this
iinventedlight. 2026. "Kubernetes labels, selectors and annotations." iinventedlight Library, iil:note:ywp947qg, version of 2026-11-04. https://iinventedlight.com/library/notes/kubernetes-labels-selectors/. License: CC-BY-4.0.
@misc{iil_note_ywp947qg,
author = {{iinventedlight}},
title = {{Kubernetes labels, selectors and annotations}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-04},
url = {https://iinventedlight.com/library/notes/kubernetes-labels-selectors/},
note = {Permanent ID iil:note:ywp947qg. License: CC-BY-4.0.},
}
Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com.
For language models and agents: start at /llms.txt. This page in Markdown: /library/notes/kubernetes-labels-selectors.md.