5.8 Kubernetes Object Naming Model
Kubernetes Object Naming Model defines how resources are uniquely identified and structured within a cluster's namespace.
Kubernetes Object Naming Model is the set of syntactic rules, uniqueness scopes, and identifier conventions that govern how object names, namespaces, labels, and other string identifiers must be formed throughout the API, ensuring names remain valid as DNS labels, Linux filesystem paths, and other downstream representations that Kubernetes and its ecosystem tooling ultimately depend on.
Core Naming Constraints
DNS Subdomain Names
Most resource names must conform to the RFC 1123 DNS subdomain format, meaning they may contain lowercase alphanumeric characters, hyphens, and dots, must start and end with an alphanumeric character, and are limited to 253 characters, a constraint chosen because object names frequently end up embedded in DNS records and hostnames.
DNS Label Names
A stricter subset of resources, including Namespace names, require conformance to the RFC 1123 DNS label format specifically, limited to 63 characters and disallowing dots, since these names may need to function as a single segment within a DNS hierarchy rather than a full subdomain.
Path Segment Names
Some names must additionally satisfy path segment safety requirements, disallowing characters that would be problematic if the name were embedded directly into a URL or filesystem path, such as ., .., or the % character.
Uniqueness Scope
Namespace-Scoped Uniqueness
For namespaced resources, an object's name need only be unique within its namespace; two different namespaces can each contain a Pod named worker, and the two are entirely distinct objects distinguished by their differing namespace, not by their name alone.
Cluster-Scoped Uniqueness
Cluster-scoped resources, such as Namespace, Node, PersistentVolume, and ClusterRole, require globally unique names across the entire cluster, since there is no enclosing scope to disambiguate two objects that happen to share a name.
Kind-Relative Uniqueness
Uniqueness of a name is always relative to a specific resource type within its scope; a Pod and a Service can both be named worker within the same namespace without conflict, since names are only required to be unique among objects of the same kind.
The generateName Mechanism
Automatic Suffix Generation
When a client sets generateName instead of name, the API server appends a short random suffix to the supplied prefix and retries name generation automatically if a collision is detected, a pattern extensively used by controllers that create many instances of an object type, such as Pods generated from a ReplicaSet template.
Trade-Offs of Generated Names
Because the exact final name is not known until after creation succeeds, clients relying on generateName must read back the created object's actual assigned name from the API response rather than assuming any particular value in advance.
Label and Annotation Key Naming
Optional Prefix Segment
Label and annotation keys may include an optional prefix, separated from the name portion by a forward slash, itself required to be a valid DNS subdomain, commonly used to namespace keys under a domain the defining project or organization controls, such as app.kubernetes.io/name.
Name Segment Constraints
The name portion of a label or annotation key, and label values themselves, are restricted to a shorter length limit and a narrower character set than general object names, reflecting their use as compact, frequently indexed metadata rather than free-form descriptive text.
UID as a Naming Complement
Distinguishing Reused Names
Because names can be reused after an object is deleted, particularly within the same namespace, the system-assigned uid field exists specifically to distinguish between an original object and a later object that happens to reuse the same name, which matters for controllers and audit systems that need to track a specific object instance unambiguously over time.
Practical Naming Conventions in Practice
Reflecting Purpose and Environment
While the API enforces only syntactic constraints, common conventions layer semantic structure onto names, such as encoding an application, component, or environment into a resource's name or its labels, improving human readability and enabling label-selector-based automation without violating any of the underlying syntactic naming rules.
Consistency Across Related Objects
Controllers commonly derive the names of objects they create from a parent object's name plus a deterministic or generated suffix, such as a Deployment-derived ReplicaSet name combining the Deployment's name with a hash of its pod template, keeping generated object names traceable back to their origin while still respecting uniqueness constraints.