skip to content
Alvin Lucillo

Kustomize patch

/ 1 min read

Yesterday, we saw how to output k8s resources using kustomize. But that example has no patch. Example below introduces patchesStrategicMerge, which is a deprecated way to change the base file. In the example below, the output changed the image from nginx to nginx:1.25

kustomize build test/
# Warning: 'patchesStrategicMerge' is deprecated. Please use 'patches' instead. Run 'kustomize edit fix' to update your Kustomization automatically.
apiVersion: v1
kind: Pod
metadata:
  creationTimestamp: null
  labels:
    run: po
  name: po
spec:
  containers:
  - args:
    - test
    image: nginx:1.25
    name: po
    resources: {}
  dnsPolicy: ClusterFirst
  restartPolicy: Always
status: {}

directory tree:

├── test
   ├── base
   └── po.yaml
   ├── kustomization.yaml
   └── patch
       └── po-patch.yaml

po.yaml

apiVersion: v1
kind: Pod
metadata:
  creationTimestamp: null
  labels:
    run: po
  name: po
spec:
  containers:
    - args:
        - test
      image: nginx
      name: po
      resources: {}
  dnsPolicy: ClusterFirst
  restartPolicy: Always
status: {}

po-patch.yaml

apiVersion: v1
kind: Pod
metadata:
  name: po
spec:
  containers:
    - name: po
      image: nginx:1.25

kustomization.yaml

apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
  - ./base/po.yaml
patchesStrategicMerge:
  - ./patch/po-patch.yaml