Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 525
jobevers Avatar asked Dec 06 '19 22:12

jobevers


2 Answers

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.

like image 124
acid_fuji Avatar answered Sep 23 '22 02:09

acid_fuji


Something like this seems to work to append an imagePullSecret:

patches:
    -   target:
            kind: Deployment
        patch: |-
            - op: add
              path: /spec/template/spec/imagePullSecrets/-
              value:
                name: regcred
    -   target:
            kind: CronJob
        patch: |-
            - op: replace
              path: /spec/jobTemplate/spec/template/spec/imagePullSecrets
              value:
                - name: regcred

Or more simply, you can just run this once:

kubectl patch serviceaccount default -p '{"imagePullSecrets": [{"name": "regcred"}]}'
like image 28
mpen Avatar answered Sep 24 '22 02:09

mpen