我已经为我的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卷。在升级窗格上进行描述时,我会看到以下错误:
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映像打包在一起,因此我认为它应该存在。 当它进入Failed状态时,我无法执行到挂接窗格中。 有人可以帮我吗?
[更新]我添加了一个sleep命令来进入Pod,并检查脚本是否可用以及安装路径是否存在。一切都很好。我不明白为什么会出现此错误。
答案 0 :(得分:5)
好像我需要以不同的方式给出命令:
command: ["/bin/sh", "-c", "scripts/preUpgradeScript.sh","{{ .Values.pvc.shared_storage_path }}/{{ template "fullname" . }}"]