Kustomize best practice to apply the same patch to multiple base files

Viewed 313

I have an application with different versions. The base resource file for each version is slightly different. But the patch which needs to be applied to the base file is same. What should be the best structure to apply the same patch to different base resource and have different output files respectively.

/base1/
     /app-v1
     /kustomization.yaml
/base2/
     /app-v2
     /kustomization.yaml
/overlays/
     /dev/      
     /staging/ 

How should I specify the resource to make the overlay and patch in base kustomization.yaml which are same to v1 and v2 apply to the different base files?

Ideally, use different kustomize build command for different base but using same patch file.

1 Answers

One way to do it would be to have a kustomization file in /overlays/, including patches and configurations from dev/ and staging/. Eg:

$> cat ./overlays/kustomization.yaml
resources:
- ./dev/foo.yaml
- ./staging/bar.yaml

patchesJson6902:
- target:
    version: v1
    groups: apps
    kind: Deployment
    name: my-app
  patch: ./dev/patch-deploy.yaml

And include that overlays folder from your base1 and base2 kustomization:

$> cat ./base1/kustomization.yaml
resources:
- ./app-v1/stuff.yaml
- ../overlays/
[...]
$> cat ./base2/kustomization.yaml
resources:
[...]
- ../overlays/

Then, you can run kustomization from either base folder, while they would all process the content of your overlays folder.

Related