5.7 Kubernetes Object Metadata Model
Kubernetes Object Metadata Model defines the structured data that describes the identity, labels, and lifecycle of resources within a Kubernetes cluster.
Kubernetes Object Metadata Model is the detailed set of conventions governing the fields nested within every object's metadata section, covering identity, labeling, annotation, versioning, ownership, and deletion-lifecycle fields, all of which exist independently of an object's specific kind and instead form a shared vocabulary that generic tooling, controllers, and access-control systems rely on uniformly.
Identity and Namespacing
Name and GenerateName
The name field provides a unique identifier for an object within its scope, while an alternative generateName field can be supplied instead, instructing the API server to append a random suffix and generate a unique name automatically, commonly used when a controller creates many similarly-purposed objects, such as Pods from a ReplicaSet.
Namespace Scoping
For namespaced resources, namespace determines the logical partition an object belongs to, with uniqueness of name guaranteed only within that namespace, allowing the same name to be reused independently across different namespaces without collision.
UID as a Permanent Identifier
The uid field is assigned once by the API server at creation and never reused, even after the object is deleted, providing a stable identity that distinguishes a given object instance from any future object that might later be created with the same name and namespace.
Labels and Selection
Label Structure and Constraints
Labels are key-value string pairs subject to specific syntax constraints on length and allowed characters, including an optional prefix segment for namespacing label keys, such as app.kubernetes.io/name, which is a widely adopted convention for common label semantics across the ecosystem.
Selectors as the Consumption Mechanism
Label selectors, either equality-based or set-based, are used throughout the object model to associate one object with a group of others, such as a Service selecting the Pods it routes traffic to, or a NetworkPolicy selecting the Pods it applies to, making labels the primary mechanism for expressing loosely coupled relationships.
Recommended Label Conventions
The project publishes a set of recommended common labels, covering concerns like application name, instance, version, component, and managing tool, intended to make objects from different tools and teams interoperable with shared dashboards and automation that key off these conventional labels.
Annotations for Extensible Metadata
Free-Form Attachment of Data
Unlike labels, annotations are not indexed for selection and are intended to hold arbitrary metadata that tools or humans want attached to an object, such as a checksum used by a deployment tool to detect configuration drift, or a description intended purely for human readers.
Structured Data in Annotations
While annotation values are simple strings, it is common practice to store structured data such as JSON within an annotation value, a pattern used, for example, by kubectl apply to record the last-applied configuration for three-way merge diffing on subsequent applies.
Ownership and Garbage Collection
OwnerReferences
The ownerReferences field lists other objects that this object is logically owned by, each entry including the owner's kind, name, and UID, along with flags such as controller and blockOwnerDeletion that influence garbage collection and deletion-blocking behavior.
Cascading Deletion Behavior
The garbage collector controller walks ownership chains established through ownerReferences to determine which dependent objects should be automatically deleted when an owner is removed, supporting both foreground deletion, which blocks owner removal until dependents are gone, and background deletion, which removes the owner immediately and cleans up dependents asynchronously.
Versioning and Concurrency Control
resourceVersion
resourceVersion is an opaque value, backed by etcd's internal revision mechanism, that changes every time an object is modified, and is used to implement optimistic concurrency control: a client submitting an update along with a stale resourceVersion will have the update rejected, preventing lost updates from concurrent writers.
generation
generation is a monotonically increasing integer incremented only when spec changes, distinct from resourceVersion, which changes on any modification including status updates, allowing controllers to detect specifically when desired state has changed versus when only observed state was updated.
Finalizers and Deletion Lifecycle
Blocking Deletion Until Cleanup Completes
finalizers is a list of identifier strings that must all be removed before an object is permanently deleted; when a delete request is issued against an object with finalizers present, the API server sets a deletionTimestamp but keeps the object present until every controller responsible for a listed finalizer has completed its cleanup and removed its entry.
Common Finalizer Use Cases
Finalizers are commonly used to ensure external resources, such as a cloud load balancer or a storage volume, are properly deprovisioned before the corresponding Kubernetes object disappears, preventing orphaned external state that would otherwise be left behind after deletion.
Server-Side Apply Field Tracking
managedFields
The managedFields entry records which fields within an object are currently owned by which field manager, such as a specific controller or kubectl, enabling server-side apply to merge concurrent edits from multiple actors intelligently rather than having each full update blindly overwrite the entire object.