【发布时间】:2022-10-15 01:37:44
【问题描述】:
我创建了 Kubernetes 作业并创建了作业,但在部署到 Kubernetes 集群时失败。当我尝试使用 Helm 重新部署它时,该作业不会重新部署(与微服务部署不同,删除旧作业并重新创建新作业)。
如何在不手动删除 Kubernetes 的情况下完成这个重新部署工作?我可以告诉它重新创建容器吗?
job.yaml 包含:
apiVersion: batch/v1
kind: Job
metadata:
name: "{{ .Release.Name }}-init-job"
namespace: {{ .Release.Namespace }}
spec:
template:
metadata:
annotations:
linkerd.io/inject: disabled
"helm.sh/hook-delete-policy": before-hook-creation
"helm.sh/hook": pre-install,pre-upgrade,pre-delete
"helm.sh/hook-weight": "-5"
spec:
serviceAccountName: {{ .Release.Name }}-init-service-account
containers:
- name: app-installer
image: some image
command:
- /bin/bash
- -c
- echo Hello executing k8s init-container
securityContext:
readOnlyRootFilesystem: true
restartPolicy: OnFailure
作业没有重新部署
kubectl get jobs -n namespace
NAME COMPLETIONS DURATION AGE
test-init-job 0/1 13h 13h
kubectl 描述作业 test-init-job -n test
Name: test-init-job
Namespace: test
Selector: controller-uid=86370470-0964-42d5-a9c1-00c8a462239f
Labels: app.kubernetes.io/managed-by=Helm
Annotations: meta.helm.sh/release-name: test
meta.helm.sh/release-namespace: test
Parallelism: 1
Completions: 1
Start Time: Fri, 14 Oct 2022 18:03:31 +0530
Pods Statuses: 0 Running / 0 Succeeded / 1 Failed
Pod Template:
Labels: controller-uid=86370470-0964-42d5-a9c1-00c8a462239f
job-name=test-init-job
Annotations: helm.sh/hook: pre-install,pre-upgrade
helm.sh/hook-delete-policy: before-hook-creation,hook-succeeded
helm.sh/hook-weight: -5
linkerd.io/inject: disabled
Service Account: test-init-service-account
Containers:
test-app-installer:
Image: artifactory/test-init-container:1.0.0
Port: <none>
Host Port: <none>
Environment:
test.baseUrl: baser
test.authType: basic
test.basic.username: jack
test.basic.password: password
Mounts:
/etc/test/config from test-installer-config-vol (ro)
Volumes:
test-installer-config-vol:
Type: ConfigMap (a volume populated by a ConfigMap)
Name: test-installer-config-files
Optional: false
Events: <none>
【问题讨论】:
-
当你重新部署它时,有什么改变吗? Job 的一般模型是它只会运行一次,而 IME 在您尝试在 Helm 中管理它时可能会导致问题。添加Helm hook annotation 是否使其以您期望的方式运行? (如果这是您想要的行为,我可以进一步扩展。)
-
我已经更新了我尝试使用 hooks 的 yaml 文件。每次进行 helm install 时,我都希望重新创建/重新部署工作。但作业不会被自动删除,它会引发异常。我需要手动删除它以重新部署作业。
-
使用您添加的 Helm 钩子注释,我希望每个
helm upgrade命令删除并重新创建作业。在运行第一次升级之前,您可能需要再次删除它。 -
kubectl get jobs -n namespace NAME COMPLETIONS DURATION AGE test-init-job 0/1 13h 13h
-
它没有被重新部署
标签: kubernetes kubernetes-helm kubectl kubernetes-pod