6.13 Kubernetes Manifest Patch Behavior
Kubernetes Manifest Patch Behavior explains how updates are applied to running Kubernetes workloads through structured configuration changes.
Kubernetes Manifest Patch Behavior is the practice of authoring a partial manifest fragment, a patch, as its own standalone declarative artifact rather than a complete object description, intended to be layered on top of a base manifest by tooling before submission, a pattern distinct from issuing an ad hoc PATCH API call and instead treating the partial change itself as a durable, version-controlled piece of configuration.
Patches as Standalone Declarative Fragments
A Fragment, Not a Full Object
A patch manifest typically includes just enough of an object's identifying fields, kind, name, and sometimes namespace, along with only the specific fields being changed, deliberately omitting everything else about the target object, since its purpose is to express a targeted modification rather than a complete configuration.
Distinguishing Patch Files From Patch Requests
While the underlying patch formats, strategic merge patch and JSON Patch, are the same mechanisms used for a live PATCH API request, a patch manifest as an authored artifact exists as a file within a source repository, applied by a build or templating step before anything is submitted to the cluster, rather than being issued directly as an isolated API call.
Strategic Merge Patches as Overlay Files
Structure of a Strategic Merge Patch File
A strategic merge patch file mirrors the shape of the target object but includes only the fields being overridden, relying on the same list-merge-by-key semantics used by the API's strategic merge patch mechanism, making it a natural fit for expressing environment-specific overrides, such as changing a container's resource limits for a production overlay.
Common Use in Overlay Tooling
Kustomize, in particular, relies heavily on strategic merge patch files as one of its primary patch mechanisms, letting a base manifest remain untouched while separate overlay directories each contain small patch files expressing only what differs for that particular environment or deployment target.
JSON 6902 Patches as Precise Operation Lists
Structure of a JSON Patch File
A JSON Patch file, following RFC 6902, expresses a change as an explicit list of operations, each with a path, an op such as replace, add, or remove, and, where applicable, a value, offering precise, unambiguous control over exactly what changes within the target object's structure.
When Precision Matters More Than Readability
JSON Patch files are favored over strategic merge patches when an operation needs to target a specific array index, remove a specific list element outright, or perform a change that strategic merge patch's key-based list merging cannot express cleanly, trading some readability for exactness.
Patch Targeting
Identifying Which Object a Patch Applies To
A patch file must unambiguously identify its target, typically through a target selector specifying kind, name, and optionally namespace or a label selector, which the applying tool resolves against the base manifests to determine exactly which object the patch's changes should be merged into before submission.
Patches Targeting Multiple Objects
Some patch tooling supports applying a single patch fragment against multiple matching objects simultaneously, using a label selector as the target rather than a single specific name, useful for applying a consistent change, such as adding a common annotation, across an entire set of related objects in one declarative step.
Patch Composition and Layering
Multiple Patches Applied in Sequence
A base manifest can have several patches applied to it in a defined order, each contributing its own targeted change, with the final resulting object reflecting the cumulative effect of every patch applied in sequence, a pattern that lets configuration variation be decomposed into small, individually reviewable pieces rather than one large, environment-specific full manifest copy.
Ordering Sensitivity
Because patches are applied in sequence and later patches can affect fields touched by earlier ones, the order in which patches are composed matters and is typically explicitly and deterministically defined by the overlay or templating tool's configuration, rather than left to be inferred from file system ordering or other implicit cues.
Patches Versus Full Manifest Duplication
Reducing Duplication Across Environments
The core motivation for authoring changes as patches rather than fully duplicated manifests per environment is reducing maintenance burden: a shared base manifest changes in one place, while only the genuinely environment-specific differences live in small, focused patch files, reducing the risk of environments silently drifting apart due to a change applied to one full manifest copy but forgotten in another.