我有一个 Helm 图,用于将用户列表添加到集群中,但我想修改我的 default
服务帐户以包含图像拉取 secret 。 helm 中似乎没有任何补丁功能。
安装后 Hook 是我能做的最好的吗?
最佳答案
我遇到过同样的问题。我所做的是:
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: default
namespace: YOUR_NAMESPACE
rules:
- apiGroups:
- ""
resources:
- serviceaccounts
verbs:
- get
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: default
namespace: YOUR_NAMESPACE
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: default
subjects:
- kind: ServiceAccount
name: default
namespace: YOUR_NAMESPACE
进而:
apiVersion: batch/v1
kind: Job
metadata:
name: create-image-pull-secret
annotations:
"helm.sh/hook": pre-install
"helm.sh/hook-delete-policy": hook-succeeded
spec:
template:
spec:
restartPolicy: Never
containers:
- name: k8s
image: google/cloud-sdk
imagePullPolicy: IfNotPresent
command: ["/bin/sh","-c", "kubectl patch serviceaccount default -p '{\"imagePullSecrets\": [{\"name\": \"YOUR_SECRET_NAME\"}]}'"]
请注意,我使用
pre-install
钩。我这样做是因为我需要 imagePullSecret 为我的子依赖项工作。此外,patch 命令允许使用尚不存在的 secret 名称。
关于kubernetes - helm patch 默认服务帐号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55503893/