运行 个通过 Helm 挂钩的脚本
Running scripts via Helm hooks
我已经为我的 Helm chart 编写了升级前和 Post-upgrade 挂钩,当我进行 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:
"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
containers:
- name: pre-upgrade-job
image: {{ .Values.registry }}/{{ .Values.imageRepo }}:{{ .Values.imageTag }}
imagePullPolicy: {{ .Values.imagePullPolicy }}
volumeMounts:
- 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" . }}']
volumes:
- name: shared-pvc
persistentVolumeClaim:
claimName: {{ template "fullname" . }}-shared-pv-claim
我的期望是挂钩应该能够将信息写入升级前已创建的 PVC 卷。当我描述升级 pods 时,我可以看到以下错误:
Error: failed to start container "pre-upgrade-job": Error response from daemon: oci runtime error: container_linux.go:247: starting container process caused "exec: \"/bin/sh -c scripts/preUpgradeScript.sh /opt/flink/share/myfl-flink\": stat /bin/sh -c scripts/preUpgradeScript.sh /opt/flink/share/myfl-flink: no such file or directory"
钩子不是在 运行 命令之前先挂载卷吗?另外,我将脚本与 docker 图像打包在一起,所以我相信它应该在那里。
当 hook pod 进入失败状态时,我无法执行它。
谁能帮我解决这个问题?
[更新]我添加了一个sleep命令进入pod,检查脚本是否可用,挂载路径是否存在。一切看起来都很好。我不明白为什么会出现这个错误。
看来我需要以不同的方式给出命令:
command: ["/bin/sh", "-c", "scripts/preUpgradeScript.sh","{{ .Values.pvc.shared_storage_path }}/{{ template "fullname" . }}"]
我已经为我的 Helm chart 编写了升级前和 Post-upgrade 挂钩,当我进行 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:
"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
containers:
- name: pre-upgrade-job
image: {{ .Values.registry }}/{{ .Values.imageRepo }}:{{ .Values.imageTag }}
imagePullPolicy: {{ .Values.imagePullPolicy }}
volumeMounts:
- 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" . }}']
volumes:
- name: shared-pvc
persistentVolumeClaim:
claimName: {{ template "fullname" . }}-shared-pv-claim
我的期望是挂钩应该能够将信息写入升级前已创建的 PVC 卷。当我描述升级 pods 时,我可以看到以下错误:
Error: failed to start container "pre-upgrade-job": Error response from daemon: oci runtime error: container_linux.go:247: starting container process caused "exec: \"/bin/sh -c scripts/preUpgradeScript.sh /opt/flink/share/myfl-flink\": stat /bin/sh -c scripts/preUpgradeScript.sh /opt/flink/share/myfl-flink: no such file or directory"
钩子不是在 运行 命令之前先挂载卷吗?另外,我将脚本与 docker 图像打包在一起,所以我相信它应该在那里。 当 hook pod 进入失败状态时,我无法执行它。 谁能帮我解决这个问题?
[更新]我添加了一个sleep命令进入pod,检查脚本是否可用,挂载路径是否存在。一切看起来都很好。我不明白为什么会出现这个错误。
看来我需要以不同的方式给出命令:
command: ["/bin/sh", "-c", "scripts/preUpgradeScript.sh","{{ .Values.pvc.shared_storage_path }}/{{ template "fullname" . }}"]