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?
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.
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"}]}'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With