理解 Kubernetes Job 中的 backoffLimit
·
回答问题
我在 kubernetes 中使用 schedule(8 * * * *
) 创建了一个Cronjob
,job 的backoffLimit
默认为 6,pod 的RestartPolicy
为Never
,pod 被故意配置为 FAIL。据我了解,(对于带有restartPolicy : Never
的 podSpec)作业控制器将尝试创建backoffLimit
数量的 pod,然后将作业标记为Failed
,因此,我预计在Error
状态下会有 6 个 pod。
这是实际 Job 的状态:
status:
conditions:
- lastProbeTime: 2019-02-20T05:11:58Z
lastTransitionTime: 2019-02-20T05:11:58Z
message: Job has reached the specified backoff limit
reason: BackoffLimitExceeded
status: "True"
type: Failed
failed: 5
为什么只有 5 个失败的 pod 而不是 6 个?还是我对backoffLimit
的理解不正确?
Answers
简而言之:您可能看不到所有创建的 pod,因为 cronjob 中的计划周期太短。
如文档中所述:
与作业关联的失败 Pod 由作业控制器重新创建,并以指数回退延迟(10 秒、20 秒、40 秒......)的上限为 6 分钟。如果在 Job 的下一次状态检查之前没有出现新的失败 Pod,则将重置回退计数。
如果在作业控制器有机会重新创建 pod 之前安排了新作业(考虑到上次失败后的延迟),作业控制器会重新从一个开始计数。
我使用以下.yaml
在 GKE 中重现了您的问题:
apiVersion: batch/v1beta1
kind: CronJob
metadata:
name: hellocron
spec:
schedule: "*/3 * * * *" #Runs every 3 minutes
jobTemplate:
spec:
template:
spec:
containers:
- name: hellocron
image: busybox
args:
- /bin/cat
- /etc/os
restartPolicy: Never
backoffLimit: 6
suspend: false
此作业将失败,因为文件/etc/os
不存在。
这是其中一项工作的kubectl describe
输出:
Name: hellocron-1551194280
Namespace: default
Selector: controller-uid=b81cdfb8-39d9-11e9-9eb7-42010a9c00d0
Labels: controller-uid=b81cdfb8-39d9-11e9-9eb7-42010a9c00d0
job-name=hellocron-1551194280
Annotations: <none>
Controlled By: CronJob/hellocron
Parallelism: 1
Completions: 1
Start Time: Tue, 26 Feb 2019 16:18:07 +0100
Pods Statuses: 0 Running / 0 Succeeded / 6 Failed
Pod Template:
Labels: controller-uid=b81cdfb8-39d9-11e9-9eb7-42010a9c00d0
job-name=hellocron-1551194280
Containers:
hellocron:
Image: busybox
Port: <none>
Host Port: <none>
Args:
/bin/cat
/etc/os
Environment: <none>
Mounts: <none>
Volumes: <none>
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal SuccessfulCreate 26m job-controller Created pod: hellocron-1551194280-4lf6h
Normal SuccessfulCreate 26m job-controller Created pod: hellocron-1551194280-85khk
Normal SuccessfulCreate 26m job-controller Created pod: hellocron-1551194280-wrktb
Normal SuccessfulCreate 26m job-controller Created pod: hellocron-1551194280-6942s
Normal SuccessfulCreate 25m job-controller Created pod: hellocron-1551194280-662zv
Normal SuccessfulCreate 22m job-controller Created pod: hellocron-1551194280-6c6rh
Warning BackoffLimitExceeded 17m job-controller Job has reached the specified backoff limit
请注意创建 podhellocron-1551194280-662zv
和hellocron-1551194280-6c6rh
之间的延迟。
更多推荐
所有评论(0)