Skip to main content
This article explains two methods for defining patches in Kubernetes: JSON 6902 patches and strategic merge patches. You have the flexibility to define patches either inline within the kustomization.yaml file or by referencing external patch files. Inline patches consolidate everything in one file, while external files keep your kustomization.yaml concise, especially when managing numerous patches.

JSON 6902 Patches

Inline Definition in kustomization.yaml

Below is an example of an inline patch applied to the “api-deployment”:

Referencing an External Patch File

Alternatively, you can reference a separate file. In this example, the external file (replica-patch.yaml) is used for the “nginx-deployment”:
In the external file (replica-patch.yaml), the patch is defined as follows:

Strategic Merge Patches

For strategic merge patches, you can similarly choose between inline definitions or referencing an external file.

Inline Strategic Merge Patch in kustomization.yaml

The following example shows an inline strategic merge patch for the “api-deployment”:

Using an External YAML File for Strategic Merge Patch

To reference a file for a strategic merge patch, simply include the file path in your kustomization.yaml:
Both inline definitions and separate patch files are valid options. Choose the approach that best suits your project structure and maintenance preferences.

Summary Table

Using external patch files is particularly beneficial if you have a high number of patches or if you want to keep your kustomization.yaml lean and easy to manage. For more in-depth information and best practices on patching in Kubernetes, explore the Kubernetes Documentation.

Watch Video