问题描述
我有一个基于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
paralleism: 1
template:
metadata:
name: pi
spec:
containers:
- name: pi
image: perl
command: ["exit", "1"]
restartPolicy: Never
我想运行一次此作业,如果失败则不要重新启动.使用comand出口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.
有可能吗?怎么样?
推荐答案
如果您希望使用一次尝试的命令运行程序,则可能应该创建裸机舱,因为该作业将尝试执行命令,直到成功或有效期限为止被满足.
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.
只需从您的模板创建广告连播:
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-如何只运行一次作业的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!