Kubernetes cronjobs`startingDeadlineSeconds`到底是什么意思? [英] What does Kubernetes cronjobs `startingDeadlineSeconds` exactly mean?

查看:1057
本文介绍了Kubernetes cronjobs`startingDeadlineSeconds`到底是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Kubernetes中 cronjobs 中,它在

In Kubernetes cronjobs, It is stated in the limitations section that

如果CronJob控制器在CronJob的开始时间之前到开始时间加上startingDeadlineSeconds的时间内没有运行或中断,则作业可能无法运行,或者该跨度涵盖多个开始时间并且concurrencyPolicy不允许并发

Jobs may fail to run if the CronJob controller is not running or broken for a span of time from before the start time of the CronJob to start time plus startingDeadlineSeconds, or if the span covers multiple start times and concurrencyPolicy does not allow concurrency.

我从中了解到,如果startingDeadlineSeconds设置为10,并且cronjob由于其计划的时间由于某种原因而无法启动,那么只要尝试将cronjob重新启动, 10秒还没有过去,但是,10秒之后,肯定不会开始,这是正确的吗?

What I understand from this is that, If the startingDeadlineSeconds is set to 10 and the cronjob couldn't start for some reason at its scheduled time, then it can still be attempted to start again as long as those 10 seconds haven't passed, however, after the 10 seconds, it for sure won't be started, is this correct?

此外,如果我将concurrencyPolicy设置为Forbid,如果已经计划运行一个cronjob,那么K8是否会将其视为失败?

Also, If I have concurrencyPolicy set to Forbid, does K8s count it as a fail if a cronjob tries to be scheduled, when there is one already running?

推荐答案

调查了Kubernetes回购,这就是CronJob控制器的工作方式:

After investigating the code base of the Kubernetes repo, so this is how the CronJob controller works:

  1. CronJob控制器会检查每10秒给定的Kubernetes客户端中的cronjob列表.
  2. 对于每个CronJob,它都会检查从lastScheduleTime到现在的持续时间中错过了多少个计划.如果有超过 100个错过的时间表,则它不会启动作业并记录事件:

  1. The CronJob controller will check the every 10 seconds the list of cronjobs in the given Kubernetes Client.
  2. For every CronJob, it checks how many schedules it missed in the duration from the lastScheduleTime till now. If there are more than 100 missed schedules, then it doesn't start the job and records the event:

"FailedNeedsStart", "Cannot determine if job needs to be started. Too many missed start time (> 100). Set or decrease .spec.startingDeadlineSeconds or check clock skew."

要注意的是重要,如果设置了字段startingDeadlineSeconds(不是nil),它将计算从startingDeadlineSeconds到现在为止发生了多少个丢失的作业.例如,如果startingDeadlineSeconds = 200,它将计算最近200秒内发生了多少个丢失的作业.计算多少个错过的时间表的确切实现可以找到这里.

It is important to note, that if the field startingDeadlineSeconds is set (not nil), it will count how many missed jobs occurred from the value of startingDeadlineSeconds till now. For example, if startingDeadlineSeconds = 200, It will count how many missed jobs occurred in the last 200 seconds. The exact implementation of counting how many missed schedules can be found here.

  1. 如果上一步错过的时间表不超过100个,CronJob控制器将检查时间now是否不在其scheduledTime + startingDeadlineSeconds时间之后,即为时不晚开始工作(超过了期限).如果还不算太晚,则CronJob控制器将继续尝试启动该作业.但是,如果为时已晚,则它不会启动作业并记录事件:

  1. In case there are not more than a 100 missed schedules from the previous step, the CronJob controller will check if the time now is not after the time of its scheduledTime + startingDeadlineSeconds, i.e. that it's not too late to start the job (passed the deadline). If it wasn't too late, the job will continue to be attempted to be started by the CronJob Controller. However, If it is already too late, then it doesn't start the job and records the event:

"Missed starting window for {cronjob name}. Missed scheduled time to start a job {scheduledTime}"

要注意的也是重要,如果设置了字段startingDeadlineSeconds(而不是nil),则表示完全没有截止日期,这意味着将尝试该作业可以通过CronJob控制器启动任何一个,而无需检查它是否稍后.

It is also important to note, that if the field startingDeadlineSeconds is set (not nil), then it means there is no deadline at all set which means the job will be attempted to start any by the CronJob controller without checking if its later or not.

因此要回答以上问题:

1.如果将startingDeadlineSeconds设置为10,并且由于某些原因cronjob无法在其计划的时间启动,那么只要这10秒还没有过去,仍然可以尝试再次启动它,但是,在10秒之后,确定不会启动,对吗?

CronJob控制器将尝试开始作业,并且如果尚未超过排定时间10秒钟,则将成功调度该作业.但是,如果期限已过,则不会在此运行中开始,并且在以后的执行中将其计为错过的计划.

The CronJob controller will attempt to start the job and it will be successfully scheduled if the 10 seconds after it's schedule time haven't passed yet. However, if the deadline has passed, it won't be started this run, and it will be counted as a missed schedule in later executions.

2.如果我将concurrencyPolicy设置为Forbid,那么如果已经计划运行一个cronjob,那么K8是否会将其视为失败?

是的,它将被计为错过的时间表.由于错过的时间表是按照我在第2点中所述的方法计算的.

Yes, it will be counted as a missed schedule. Since missed schedules are calculated as I stated above in point 2.

这篇关于Kubernetes cronjobs`startingDeadlineSeconds`到底是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆