我正在使用Helm 3的Kubernetes。
它运行在CentOS Linux 7 (Core)上。
K8S (运行检查: kubectl版本):
git版本(kubernetes):v1.21.6,go版本: go1.16.9。
头盔版本: v3.3.4
舵版(git) go1.14.9。
我需要创建一个在Pod创建之后运行的作业。
吊舱yaml:
apiVersion: v1
kind: Pod
metadata:
name: {{ include "test.fullname" . }}-mysql
labels:
app: {{ include "test.fullname" . }}-mysql
annotations:
"helm.sh/hook": post-install
"helm.sh/hook-weight": "-20"
"helm.sh/delete-policy": before-hook-creation
spec:
containers:
- name: {{ include "test.fullname" . }}-mysql
image: {{ .Values.mysql.image }}
imagePullPolicy: IfNotPresent
env:
- name: MYSQL_ROOT_PASSWORD
value: "12345"
- name: MYSQL_DATABASE
value: test
工作:
apiVersion: batch/v1
kind: Job
metadata:
name: {{ include "test.fullname" . }}-migration-job
labels:
app: {{ include "test.fullname" . }}-migration-job
annotations:
"helm.sh/hook": post-install
"helm.sh/hook-weight": "-10"
"helm.sh/hook-delete-policy": hook-succeeded, hook-failed
spec:
parallelism: 1
completions: 1
backoffLimit: 1
template: #PodTemplateSpec (Core/V1)
spec: #PodSpec (core/v1)
initContainers: # regular
- name: wait-mysql
image: bitnami/kubectl
imagePullPolicy: IfNotPresent
args:
- wait
- pod/{{ include "test.fullname" . }}-mysql
- --namespace={{ .Release.Namespace }}
- --for=condition=ready
- --timeout=120s
containers:
- name: {{ include "test.fullname" . }}
image: {{ .Values.myMigration.image }}
imagePullPolicy: IfNotPresent
command: {{- toYaml .Values.image.entrypoint | nindent 12 }}
args: {{- toYaml .Values.image.cmd | nindent 12}}
MySQL是MySQL 5.6图像。
当我编写上面的内容时,也运行helm install test ./test --namespace test --create-namespace
即使我更改了预安装挂钩(用于Pod和作业),但作业永远不会运行。
在这两种情况下,我都会收到消息(需要按--以退出),我也不希望这种行为:
Pod测试-mysql等待Pod测试-mysql正在运行.
在本例中,当我在作业中输入“bug”(例如:containersx
而不是container
)时,我不会收到任何通知,说明我有错误的语法。
也许因为MySQL正在运行(还没有完成),我可以强制转到下一个由钩子声明的yaml吗?(就连我都宣布了Pod和Job的正确订单。吊舱应在作业前运行)。
出了什么问题,我怎样才能确保在工作之前就创造出吊舱呢?当吊舱开始运行时,我的工作会在那之后运行?
谢谢。
发布于 2022-03-25 17:01:39
按照您的配置,您需要为作业精确地设置post-install
钩子,因为它应该在将所有资源加载到Kubernetes之后执行。在Pod和Job上执行pre-install
钩子时,在加载图表的其余部分之前就会运行它,这似乎阻止了作业的启动。
https://stackoverflow.com/questions/71351229
复制相似问题