我已经在kubernetes中创建了一个带有schedule(Cronjob)的8 * * * *,作业的backoffLimit默认为6,pod的RestartPolicy设置为Never,这些Pod被故意配置为FAIL。据我了解,(对于带有restartPolicy : Never的podSpec),作业 Controller 将尝试创建backoffLimit数量的Pod,然后将其标记为Failed,因此,我期望Error状态下将有6个Pod。

这是工作的实际状态:

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个失败的 pods 而不是6个?还是我对backoffLimit的理解不正确?

最佳答案

简而言之:您可能看不到所有已创建的 pods ,因为cronjob中的计划时间很短。

documentation中所述:



如果在Job Controller 有机会重新创建Pod之前计划了新作业(请牢记先前故障后的延迟),则Job Controller 将再次从一个开始计数。

我使用以下.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

注意创建pod hellocron-1551194280-662zvhellocron-1551194280-6c6rh之间的延迟。

关于kubernetes - 了解Kubernetes Job中的backoffLimit,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/54825671/

10-16 13:56
查看更多