在 Helm 中的预升级挂钩中传递参数
Passing arguments inside pre-upgrade hook in Helm
我的 Helm 图表中有一个升级前挂钩,如下所示:
apiVersion: batch/v1
kind: Job
metadata:
name: "{{.Release.Name}}-preupgrade"
labels:
heritage: {{.Release.Service | quote }}
release: {{.Release.Name | quote }}
chart: "{{.Chart.Name}}-{{.Chart.Version}}"
annotations:
# This is what defines this resource as a hook. Without this line, the
# job is considered part of the release.
"helm.sh/hook": pre-upgrade
"helm.sh/hook-weight": "0"
"helm.sh/hook-delete-policy": hook-succeeded
spec:
template:
metadata:
name: "{{.Release.Name}}"
labels:
heritage: {{.Release.Service | quote }}
release: {{.Release.Name | quote }}
chart: "{{.Chart.Name}}-{{.Chart.Version}}"
spec:
restartPolicy: Never
securityContext:
# Because we are running as non root user and group id/User id of the flink user is 1000/1000.
fsGroup: {{ .Values.spec.securityContext.fsGroup }}
runAsNonRoot: {{ .Values.spec.securityContext.runAsNonRootFlag }}
runAsUser: {{ .Values.spec.securityContext.runAsUser }}
containers:
- name: pre-upgrade-job
image: {{ .Values.registry }}/{{ .Values.imageRepo }}:{{ .Values.imageTag }}
imagePullPolicy: {{ .Values.imagePullPolicy }}
# Got error /bin/sleep: invalid time interval 'lcm_hook'
args:
- lcm_hook
env:
# Need to add this env variable so that the custom flink conf values will be written to $FLINK_HOME/conf.
# This is needed for the hook scripts to connect to the Flink JobManager
- name: FLINK_KUBE_CONFIGMAP_PATH
value: {{ .Values.spec.config.mountPath }}
volumeMounts:
- name: {{ template "fullname" . }}-flink-config
mountPath: {{ .Values.spec.config.mountPath }}
- mountPath: {{ .Values.pvc.shared_storage_path }}/{{ template "fullname" . }}
name: shared-pvc
command: ["/bin/sh", "-c", "scripts/preUpgradeScript.sh","{{ .Values.pvc.shared_storage_path }}/{{ template "fullname" . }}"]
command: ["/bin/sleep","10"]
volumes:
- name: {{ template "fullname" . }}-flink-config
configMap:
name: {{ template "fullname" . }}-flink-config
- name: shared-pvc
persistentVolumeClaim:
claimName: {{ template "fullname" . }}-shared-pv-claim
在这里,我需要将一个名为 "lcm_hooks" 的参数传递给我的 docker 容器。但是当我这样做时,这个参数似乎覆盖了我的第二个命令 ["/bin/sleep","10"] 的参数,我得到一个错误
/bin/sleep: invalid time interval 'lcm_hook'
在升级阶段。什么是正确的方法来确保我能够将一个参数传递给我的容器,并将一个完全不同的参数传递给我在 helm hook 中的 bash 命令?
my docker container, called "lcm_hooks"
你的钩子有一个容器,它不叫 lcm_hooks
,你叫它 pre-upgrade-job
。我提到这一点是因为您可能忘记包含一段代码,或者误解了它的工作原理。
I need to pass an argument to my docker container
您的 yaml 指定了 command
和 args
,因此图像的原始 entrypoint
和 cmd
将被完全忽略。如果你想 "pass argument to container" 你应该从 yaml 中省略 command
并只覆盖 args
。
second command
您的容器规范确实指定了两个命令,这意味着只有后者会执行。如果你想同时执行它们,你应该将它们链接起来。
What is the right way to ensure that I am able to pass one argument to my container, and a totally different one to my bash command in the helm hook
您将挂钩容器与您要使用 Helm 部署的实际容器分开。
我建议您查看容器规范和 Helm 钩子文档,这可能会澄清一些事情:
我的 Helm 图表中有一个升级前挂钩,如下所示:
apiVersion: batch/v1
kind: Job
metadata:
name: "{{.Release.Name}}-preupgrade"
labels:
heritage: {{.Release.Service | quote }}
release: {{.Release.Name | quote }}
chart: "{{.Chart.Name}}-{{.Chart.Version}}"
annotations:
# This is what defines this resource as a hook. Without this line, the
# job is considered part of the release.
"helm.sh/hook": pre-upgrade
"helm.sh/hook-weight": "0"
"helm.sh/hook-delete-policy": hook-succeeded
spec:
template:
metadata:
name: "{{.Release.Name}}"
labels:
heritage: {{.Release.Service | quote }}
release: {{.Release.Name | quote }}
chart: "{{.Chart.Name}}-{{.Chart.Version}}"
spec:
restartPolicy: Never
securityContext:
# Because we are running as non root user and group id/User id of the flink user is 1000/1000.
fsGroup: {{ .Values.spec.securityContext.fsGroup }}
runAsNonRoot: {{ .Values.spec.securityContext.runAsNonRootFlag }}
runAsUser: {{ .Values.spec.securityContext.runAsUser }}
containers:
- name: pre-upgrade-job
image: {{ .Values.registry }}/{{ .Values.imageRepo }}:{{ .Values.imageTag }}
imagePullPolicy: {{ .Values.imagePullPolicy }}
# Got error /bin/sleep: invalid time interval 'lcm_hook'
args:
- lcm_hook
env:
# Need to add this env variable so that the custom flink conf values will be written to $FLINK_HOME/conf.
# This is needed for the hook scripts to connect to the Flink JobManager
- name: FLINK_KUBE_CONFIGMAP_PATH
value: {{ .Values.spec.config.mountPath }}
volumeMounts:
- name: {{ template "fullname" . }}-flink-config
mountPath: {{ .Values.spec.config.mountPath }}
- mountPath: {{ .Values.pvc.shared_storage_path }}/{{ template "fullname" . }}
name: shared-pvc
command: ["/bin/sh", "-c", "scripts/preUpgradeScript.sh","{{ .Values.pvc.shared_storage_path }}/{{ template "fullname" . }}"]
command: ["/bin/sleep","10"]
volumes:
- name: {{ template "fullname" . }}-flink-config
configMap:
name: {{ template "fullname" . }}-flink-config
- name: shared-pvc
persistentVolumeClaim:
claimName: {{ template "fullname" . }}-shared-pv-claim
在这里,我需要将一个名为 "lcm_hooks" 的参数传递给我的 docker 容器。但是当我这样做时,这个参数似乎覆盖了我的第二个命令 ["/bin/sleep","10"] 的参数,我得到一个错误
/bin/sleep: invalid time interval 'lcm_hook'
在升级阶段。什么是正确的方法来确保我能够将一个参数传递给我的容器,并将一个完全不同的参数传递给我在 helm hook 中的 bash 命令?
my docker container, called "lcm_hooks"
你的钩子有一个容器,它不叫 lcm_hooks
,你叫它 pre-upgrade-job
。我提到这一点是因为您可能忘记包含一段代码,或者误解了它的工作原理。
I need to pass an argument to my docker container
您的 yaml 指定了 command
和 args
,因此图像的原始 entrypoint
和 cmd
将被完全忽略。如果你想 "pass argument to container" 你应该从 yaml 中省略 command
并只覆盖 args
。
second command
您的容器规范确实指定了两个命令,这意味着只有后者会执行。如果你想同时执行它们,你应该将它们链接起来。
What is the right way to ensure that I am able to pass one argument to my container, and a totally different one to my bash command in the helm hook
您将挂钩容器与您要使用 Helm 部署的实际容器分开。
我建议您查看容器规范和 Helm 钩子文档,这可能会澄清一些事情: