Skip to main content
When customizing Kubernetes resources, you often need to modify lists—such as the containers array in a Deployment. Kustomize supports two patch strategies:
  • JSON 6902 patches: precise, index-based operations (add, replace, remove).
  • Strategic Merge Patches (SMP): declarative, merge-key based edits.
Below is a quick comparison:

Base Deployment Example

Every entry in spec.template.spec.containers is a YAML list item, so it begins with -.

1. Replacing a Container

1.1 JSON 6902 Patch

Add to your kustomization.yaml:
Resulting section:

1.2 Strategic Merge Patch

Create a file replace-container.yaml:
Reference it in kustomization.yaml:
Kustomize finds the item with name: nginx and updates its image.

2. Adding a Container

2.1 JSON 6902 Patch

To append at the end:
Result:
You can also insert at a specific index by replacing - with 1, 2, etc.
Using path: /containers/- always appends. For precise position, specify the index.

2.2 Strategic Merge Patch

File add-container.yaml:
In your kustomization.yaml:
The new haproxy container is appended automatically.

3. Removing a Container

Assume this deployment:

3.1 JSON 6902 Patch

To remove the second container (index 1):
After applying, only web remains.

3.2 Strategic Merge Patch

Create remove-database.yaml:
Include it in kustomization.yaml:
Kustomize deletes the container with name: database.

Watch Video

Practice Lab