Search code examples
kuberneteskustomize

kustomize: add imagePullSecrets to all deployments


I have a set of kubernetes config files that work in one environment. I'm looking to deploy into another environment where I need to add an imagePullSecrets entry to all of the Deployment configs.

I can do:

regcred-1.yaml:

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: deployment-1
spec:
  template:
    spec:
      imagePullSecrets:
      - name: regcred

kustomization.yaml:

bases:
  - ../base

patchesStrategicMerge:
  - regcred-1.yaml

and that will patch only deployment-1.

Is there a way to apply the patch to all deployments?


Solution

  • You could use patches field instead of patchesStrategicMerge in order to patch multiple resources.

    Based on this demo example you can do this by specifiyng patch and target selector:

    patches:
    - path: <PatchFile>   target:
        group: <Group>
        version: <Version>
        kind: <Kind>
        name: <Name>
        namespace: <Namespace>
        labelSelector: <LabelSelector>
        annotationSelector: <AnnotationSelector>
    

    In this case your kustomization.yaml should look like this:

    bases:
      - ../base
    
    patches:
    - path: regcred-1.yaml
     target:
       kind: Deployment
    

    Let me know if that solved your case.