kustomization.yaml or as an external file referenced from kustomization.yaml. Choosing between inline and external files depends on readability and maintainability—small tweaks are fine inline, while many or large patches are better kept in separate files.
If you have many patches, prefer keeping them in separate files and referencing those files from
kustomization.yaml to keep the kustomization manifest readable.When to use each patch type
- JSON 6902 patches are RFC 6902 JSON Patch documents (arrays of operations). They give fine-grained control (add, remove, replace, test, move) and are ideal when you need to target a precise JSON path.
- Strategic merge patches are Kubernetes-aware YAML snippets that merge with the existing object structure. They are easier to read and write for straightforward configuration changes (e.g., changing replica count, adding labels).
JSON 6902 patch
JSON 6902 uses an array of patch operations from RFC 6902. You can embed the JSON array inline inkustomization.yaml or point to an external .json file.
Inline example (in kustomization.yaml):
Strategic merge patch
Strategic merge patches are YAML fragments that Kustomize merges into the target object. They are often more concise for straightforward changes and leverage Kubernetes strategic merge semantics. Inline example (inkustomization.yaml):
Quick comparison
Best practices
- Keep
kustomization.yamlreadable: prefer external files when patches are long or numerous. - Use JSON 6902 for exact JSON path operations or scripted automation.
- Use strategic merge patches when changing structural fields that merge naturally (e.g.,
spec,metadata). - Validate JSON 6902 patch arrays for correct syntax and valid JSON (tools or CI checks can help).
Summary
- Both JSON 6902 and Strategic Merge patches can be provided inline or referenced as external files from
kustomization.yaml. - Inline patches are convenient for small edits; external files are better for organization and maintainability when dealing with many patches.
- Pick the patch style that best matches the change semantics and team readability preferences.
Links and references
- RFC 6902 — JSON Patch
- Kustomize — patches documentation: https://kubectl.docs.kubernetes.io/guides/introduction/kustomize/ (or check your Kustomize / kubectl docs for your version)
- Kubernetes API concepts: https://kubernetes.io/docs/concepts/overview/working-with-objects/kubernetes-objects/