Reuse JSON patches in kustomize

6/3/2019

I am using a JSON patch in my overlay kustomization file in order to set the image to use for my pods.

The patch itself is pretty generic:

- op: replace
  path: /spec/template/spec/containers/0/image
  value: myRegistry/myImage:myTag

And in my kustomization.yml:

patchesJson6902:
  - target:
      group: apps
      version: v1
      kind: Deployment
      name: myDeployment
    path: patch_image.yml

By using this method, I have to use a different patch for each deployment that uses a different image. Is there a way to move the patch value field up to the kustomization.yml file, where I could do something like:

patchesJson6902:
  - target:
      group: apps
      version: v1
      kind: Deployment
      name: myDeploymentA
    path: patch_image.yml
    value: myRegistry/myImageA:myTag
  - target:
      group: apps
      version: v1
      kind: Deployment
      name: myDeploymentB
    path: patch_image.yml
    value: myRegistry/myImageB:myTag
-- ITChap
json-patch
kubernetes
kustomize

0 Answers