kustomize:将 imagePullSecrets 添加到所有部署
kustomize: add imagePullSecrets to all deployments
我有一组在一个环境中工作的 kubernetes 配置文件。我希望部署到另一个环境中,我需要在其中向所有 Deployment
配置添加一个 imagePullSecrets 条目。
我能做到:
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
这只会修补 deployment-1
。
有没有办法将补丁应用到所有部署?
您可以使用 patches
字段而不是 patchesStrategicMerge
来修补多个资源。
基于这个 demo example 你可以通过指定补丁和目标选择器来做到这一点:
patches:
- path: <PatchFile> target:
group: <Group>
version: <Version>
kind: <Kind>
name: <Name>
namespace: <Namespace>
labelSelector: <LabelSelector>
annotationSelector: <AnnotationSelector>
在这种情况下,您的 kustomization.yaml
应如下所示:
bases:
- ../base
patches:
- path: regcred-1.yaml
target:
kind: Deployment
如果这解决了您的问题,请告诉我。
像这样的东西似乎可以附加一个 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
或者更简单地说,您可以 运行 这一次:
kubectl patch serviceaccount default -p '{"imagePullSecrets": [{"name": "regcred"}]}'
使用Inline Patch:
kind: Kustomization
apiVersion: kustomize.config.k8s.io/v1beta1
resources:
- ../../base
patches:
- target:
kind: Deployment
patch: |-
- op: add
path: /spec/template/spec/imagePullSecrets
value: [{ name: image-pull-secret }]
我有一组在一个环境中工作的 kubernetes 配置文件。我希望部署到另一个环境中,我需要在其中向所有 Deployment
配置添加一个 imagePullSecrets 条目。
我能做到:
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
这只会修补 deployment-1
。
有没有办法将补丁应用到所有部署?
您可以使用 patches
字段而不是 patchesStrategicMerge
来修补多个资源。
基于这个 demo example 你可以通过指定补丁和目标选择器来做到这一点:
patches:
- path: <PatchFile> target:
group: <Group>
version: <Version>
kind: <Kind>
name: <Name>
namespace: <Namespace>
labelSelector: <LabelSelector>
annotationSelector: <AnnotationSelector>
在这种情况下,您的 kustomization.yaml
应如下所示:
bases:
- ../base
patches:
- path: regcred-1.yaml
target:
kind: Deployment
如果这解决了您的问题,请告诉我。
像这样的东西似乎可以附加一个 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
或者更简单地说,您可以 运行 这一次:
kubectl patch serviceaccount default -p '{"imagePullSecrets": [{"name": "regcred"}]}'
使用Inline Patch:
kind: Kustomization
apiVersion: kustomize.config.k8s.io/v1beta1
resources:
- ../../base
patches:
- target:
kind: Deployment
patch: |-
- op: add
path: /spec/template/spec/imagePullSecrets
value: [{ name: image-pull-secret }]