how to patch selector and label service name of deployment.yaml in kustomization.yaml

Viewed 658

My Setup: GitHub(Build Pipeline) + Kustomize + Kubernetes

Kustomize structure:

--base
----deployment.yaml
----service.yaml
----kustomizationn.yaml
--env-country1
----kustomizationn.yaml
--env-country2
----kustomizationn.yaml

Issue: I am trying to patch the spec.selector.matchLabels.service and spec.template.metadata.labels.service values present in the deployment.yaml in the base.

what I tried:

  1. I tried to use patch like below:

    patches:
    - patch: |-
     - op: replace
      path: /metadata/name
      value: <serviceName>-<country>
     - op: replace
      path: /spec/selector/matchLabels/service
      value: <serviceName>-<country>
     - op: replace
      path: /spec/template/metadata/labels/service
      value: <serviceName>-<country>  
     target:
     kind: Deployment
    

Issue: these are immutable entities, hence can't be patched.

I also tried to research but was not able to find any related documentation with examples.

PS: I am not using helm.

Thanks in advance

0 Answers
Related