Kubernetes - 如何只运行一次作业 [英] Kubernetes - how to run job only once
问题描述
我有一个基于 kubernetes 网站示例的工作定义.
I have a job definition based on example from kubernetes website.
apiVersion: batch/v1
kind: Job
metadata:
name: pi-with-timeout-6
spec:
activeDeadlineSeconds: 30
completions: 1
parallelism: 1
template:
metadata:
name: pi
spec:
containers:
- name: pi
image: perl
command: ["exit", "1"]
restartPolicy: Never
我想运行一次此作业,如果失败则不重新启动.使用命令退出 1 kubernetes 尝试运行新的 pod 以获取退出 0 代码,直到达到 activeDeadlineSeconds 超时.怎样才能避免呢?我想在 kubernetes 中运行构建命令来检查编译,如果编译失败,我会得到不同于 0 的退出代码.我不想再次运行编译.
I would like run this job once and not restart if fails. With comand exit 1 kubernetes trying to run new pod to get exit 0 code until reach activeDeadlineSeconds timeout. How can avoid that? I would like run build commands in kubernetes to check compilation and if compilation fails I'll get exit code different than 0. I don't want run compilation again.
有可能吗?怎么样?
推荐答案
如果你想要一个一次性的命令运行器,你可能应该创建裸 pod,因为作业会尝试执行命令直到它成功或活动截止日期满足.
If you want a one-try command runner, you probably should create bare pod, because the job will try to execute the command until it's successful or the active deadline is met.
只需根据您的模板创建 pod:
Just create the pod from your template:
apiVersion: v1
kind: Pod
metadata:
name: pi
spec:
containers:
- name: pi
image: perl
command: ["exit", "1"]
restartPolicy: Never
这篇关于Kubernetes - 如何只运行一次作业的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!