我的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:无效的时间间隔“ lcm_hook”
在升级阶段。确保我能够将一个参数传递给我的容器,并将一个完全不同的参数传递给我在头盔挂钩中的bash命令的正确方法是什么?
答案 0 :(得分:2)
我的Docker容器称为“ lcm_hooks”
您的钩子有一个未命名为lcm_hooks
的容器,您将其命名为pre-upgrade-job
。我之所以这样说是因为您可能忘记了一段代码,或者误解了它的工作原理。
我需要将参数传递给我的docker容器
您的Yaml同时指定了command
和args
,因此图像的原始entrypoint
和cmd
将被完全忽略。如果要“将参数传递给容器”,则应从yaml中省略command
并仅覆盖args
。
第二条命令
您的容器规范确实指定了两个命令,这意味着将仅执行后者。如果要同时执行它们,则应将它们链接起来。
什么是正确的方法来确保我能够将一个参数传递给我的容器,而将一个完全不同的参数传递给我在头盔挂钩中的bash命令
您将挂钩容器与要使用Helm部署的实际容器分开。
我建议您查看容器规格和Helm钩子文档,这可能会澄清一些问题: