导语:当我们使用helm upgrade时,job资源会因为不能修改而中断。
当我们使用before-hook-creation的时候,job资源会在存在的情况下先删除,再次创建。避免因为不能修改而中断。
yaml添加部分为annotations块
apiVersion: batch/v1
kind: Job
metadata:
name: aiserverconfig-migration
labels:
job-name: aiserverconfig-migration
k8s-med-type: job
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": "-5"
# before-hook-creation,hook-succeeded 表示在创建新的 {{ .Release.Name }}-db-migration 钩子之前和在钩子成功执行之后都将删除该钩子。
#"helm.sh/hook-delete-policy": hook-succeeded
"helm.sh/hook-delete-policy": before-hook-creation
spec:
template:
metadata:
labels:
job-name: aiserverconfig-migration
spec:
initContainers:
- command: ['sh', '-c', "until nc -w 3 -zv mysql 3306 ; do echo waiting for mydb; sleep 5; done"]
image: harbor.deepwise.com/base/busybox:stable-wait-for
name: wait-for-mysql
containers:
- name: aiserverconfig-migration
image: {{ .Values.images.aiserverconfig_migration }}
command: ["sh","-c","sh /srv/aiserverconfig-migration/startup.sh"]
env:
- name: TZ
value: Asia/Shanghai
volumeMounts:
- name: migration-persistent-storage
mountPath: /root/migration/
restartPolicy: OnFailure
volumes:
- name: migration-persistent-storage
persistentVolumeClaim:
claimName: migration-pvc
初次执行时job名称似乎没有显示,重复执行几次之后查看job名并无问题。

并未经详细验证和测试。仅记录一下
参考
https://helm.sh/docs/topics/charts_hooks/#hook-deletion-policies
https://www.jianshu.com/p/1a865909d20b
2万+

被折叠的 条评论
为什么被折叠?



