---
source: https://iinventedlight.com/library/notes/kubernetes-labels-selectors.md
title: "Kubernetes labels, selectors and annotations"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "CC BY 4.0 (kubernetes/website); prose restates cited source lines"
attribution: "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)."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-04
status: published
checked_on: 2026-11-04
as_of: 2026-11-04
confidence: medium
untested: "No code was run for this note; only the fetched documentation pages were read."
category: coding-references
topic_area: "code-ai-eng: Kubernetes"
tags: ['kubernetes', 'labels', 'selectors', 'metadata']
sources:
  - id: S1
    title: "Labels and Selectors"
    publisher: Kubernetes Authors
    url: https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/
    accessed: 2026-11-04
    license: "CC BY 4.0 (kubernetes/website)"
  - id: S2
    title: "Annotations"
    publisher: Kubernetes Authors
    url: https://kubernetes.io/docs/concepts/overview/working-with-objects/annotations/
    accessed: 2026-11-04
    license: "CC BY 4.0 (kubernetes/website)"
---
# Kubernetes labels, selectors and annotations

**Answer:** 

## Labels

```yaml
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`.

```bash
kubectl get pods -l 'app=web,environment in (prod)'
```

## Annotations


```yaml
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).
