Kubernetes Label Structure
Kubernetes Label Structure defines how metadata is organized and applied to resources, enabling efficient selection and management within a Kubernetes cluster.
Kubernetes Label Structure is the precise syntactic specification governing what characters, lengths, and formats are valid for a label's key and value, a specification enforced by the API server's validation logic on every write, existing to guarantee that any label, from any source, remains safely usable as a matching criterion, a DNS-adjacent identifier, or a display element without further sanitization. While the broader label and selector model describes how labels function within the system, label structure describes the narrower, purely syntactic rules that determine whether a given key-value pair is even a legal label to begin with.
Label Key Structure
The Optional Prefix
A label key may optionally include a prefix, a DNS subdomain (such as app.kubernetes.io or example.com) followed by a forward slash, used to namespace the key and avoid collisions between labels defined by different tools, organizations, or the Kubernetes project itself; a key without a prefix is assumed to be private to the user defining it and carries no implied ownership.
The Required Name Segment
Following any prefix, the name segment of a key must be 63 characters or fewer, must begin and end with an alphanumeric character, and may otherwise contain alphanumeric characters, dashes, underscores, and dots; this segment is what most manifests actually vary, while the prefix, when present, tends to remain fixed across an entire ecosystem of related labels.
Prefix Length Constraints
The prefix portion, when present, is itself constrained to a valid DNS subdomain, meaning it must be 253 characters or fewer and follow standard DNS label formation rules for each dot-separated segment, mirroring the same constraints applied to object names elsewhere in the API.
Label Value Structure
Length and Character Constraints
A label value must be 63 characters or fewer and, like the key's name segment, must be empty or begin and end with an alphanumeric character while containing only alphanumeric characters, dashes, underscores, and dots in between; unlike keys, values never carry a prefix, since there is only ever one namespace-relevant portion to a label pair, and that role is fulfilled entirely by the key.
Empty Values Are Permitted
An empty string is a valid label value, commonly used when a label's mere presence, rather than any specific associated value, is what matters for selection purposes — a key like example.com/managed-by-team with an empty value can still be matched by an Exists set-based selector even though it carries no meaningful value payload.
Case Sensitivity and Exact Matching
Labels Are Case-Sensitive
Both label keys and values are treated as case-sensitive throughout the API, meaning Environment: Production and environment: production are entirely distinct labels from the system's perspective, a detail that has caused real confusion in projects with inconsistent casing conventions across different manifest authors or tools.
No Implicit Normalization
The API server performs no case normalization, whitespace trimming beyond what YAML parsing itself does, or other implicit transformation of label content; a label's structure as submitted is exactly its structure as stored and matched against, placing the burden of consistency entirely on whoever authors or generates the labels.
Well-Known and Reserved Prefixes
kubernetes.io and k8s.io
Label prefixes under kubernetes.io and k8s.io (and their subdomains) are reserved for use by Kubernetes system components and closely associated ecosystem projects; manifests and tools outside this reserved space are expected to choose their own prefix under a domain they control, avoiding collision with current or future system-defined label semantics.
The Recommended app.kubernetes.io Labels
The app.kubernetes.io prefix carries a documented, though non-mandatory, set of recommended label keys (name, instance, version, component, part-of, managed-by) intended to give differently authored applications a common, interoperable labeling vocabulary that generic tooling across the ecosystem can rely on without needing project-specific configuration.