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.
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 yourkustomization.yaml:
1.2 Strategic Merge Patch
Create a filereplace-container.yaml:
kustomization.yaml:
name: nginx and updates its image.
2. Adding a Container
2.1 JSON 6902 Patch
To append at the end:- with 1, 2, etc.
Using
path: /containers/- always appends. For precise position, specify the index.2.2 Strategic Merge Patch
Fileadd-container.yaml:
kustomization.yaml:
haproxy container is appended automatically.
3. Removing a Container
Assume this deployment:3.1 JSON 6902 Patch
To remove the second container (index 1):web remains.
3.2 Strategic Merge Patch
Createremove-database.yaml:
kustomization.yaml:
name: database.