Skip to main content
Kustomize supports two primary patch mechanisms for modifying Kubernetes resources: JSON 6902 patches and Strategic Merge patches. Each can be declared either inline inside 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 in kustomization.yaml or point to an external .json file. Inline example (in kustomization.yaml):
External-file example kustomization.yaml:
replica-patch.json:
Use JSON 6902 when you need explicit operations on JSON paths or when you want to script precise changes.

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 (in kustomization.yaml):
External-file example kustomization.yaml:
replica-strategic-patch.yaml:
Choose strategic merge patches when you want readable, Kubernetes-centered patches and when the changes naturally map to partial object merges.

Quick comparison

Best practices

  • Keep kustomization.yaml readable: 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.

Watch Video