Patch Overview
| Patch Type | Operation Style | Inline | External File |
|---|---|---|---|
| JSON 6902 Patch | JSON Patch RFC 6902 (add, remove, replace, etc.) | ✅ | ✅ |
| Strategic Merge Patch | Declarative field merge using Kubernetes’ native logic | ✅ | ✅ |
JSON 6902 Patches
JSON 6902 patches let you apply JSON-style operations to modify existing resources.1. Inline Definition
Embed the patch directly in yourkustomization.yaml under patchesJson6902:
2. External File
Separate the patch into its own file (replica-patch.yaml) and reference it:
kustomization.yaml
External JSON 6902 patches are ideal when you need to apply multiple operations or share patches across environments.
Strategic Merge Patches
Strategic Merge Patches allow you to declaratively merge fields into existing resources.1. Inline Definition
Define the merge patch inline inkustomization.yaml under patchesStrategicMerge:
2. External File
Store the merge patch in a file (strategic-replica-patch.yaml) and reference it:
kustomization.yaml
The
metadata.name in your patch must exactly match the target resource name; otherwise, the patch won’t be applied.Best Practices
- Use inline patches for small, one-off tweaks.
- Move to external files when your patches multiply or you need reuse.
- Group related patches in directories to manage environment overlays (e.g.,
overlays/staging,overlays/production).