Kubernetes cronjobs `startingDeadlineSeconds` 到底是什么意思?
What does Kubernetes cronjobs `startingDeadlineSeconds` exactly mean?
在 Kubernetes cronjobs, It is stated in the limitations section 中
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 由于某种原因无法在预定时间启动,那么它仍然可以尝试只要 10
秒还没有过去,就重新启动,但是,在 10
秒之后,它肯定不会启动,对吗?
此外,如果我将 concurrencyPolicy
设置为 Forbid
,如果尝试安排一个 cronjob,K8s 是否将其视为失败,而此时已经 运行?
调查 Kubernetes repo 的代码库后,CronJob 控制器的工作原理如下:
CronJob 控制器 will check the every 10 seconds 给定 Kubernetes 客户端中的 cronjobs 列表。
对于每个 CronJob,它会检查从 lastScheduleTime
到现在的持续时间内错过了多少计划。如果超过 100 missed schedules,则不会启动作业并记录事件:
"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
秒内发生了多少个错过的作业。具体实现统计错过多少可以找到here.
如果上一步错过的计划不超过 100 个,CronJob 控制器将检查时间 now
是否在其 [=19= 的时间之后],即现在开始工作还为时不晚(超过了截止日期)。如果还不算太晚,CronJob 控制器将继续尝试启动该作业。但是,如果为时已晚,则不会启动作业并记录事件:
"Missed starting window for {cronjob name}. Missed scheduled time to start a job {scheduledTime}"
另外重要 需要注意的是,如果字段 startingDeadlineSeconds
未设置,则意味着根本没有截止日期。这意味着 CronJob 控制器将尝试启动该作业,而不检查它是否晚了。
因此回答以上问题:
1.如果 startingDeadlineSeconds 设置为 10 并且 cronjob 由于某种原因无法在预定时间启动,那么只要这 10 秒没有过去,它仍然可以尝试再次启动,但是,在 10 秒之后,它肯定不会启动,这是正确的吗?
CronJob 控制器将尝试启动作业,如果在计划时间后的 10 秒还没有过去,它将成功计划。但是,如果已经过了deadline,则不会在本次运行开始执行,在后面的执行中会被算作错过了。
2。如果我将 concurrencyPolicy 设置为 Forbid,如果一个 cronjob 试图被安排,K8s 是否将其视为失败,而此时已经有一个 运行ning?
是的,这将被计为错过日程。由于错过的时间表是按照我上面第 2 点所述计算的。
在 Kubernetes cronjobs, It is stated in the limitations section 中
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 由于某种原因无法在预定时间启动,那么它仍然可以尝试只要 10
秒还没有过去,就重新启动,但是,在 10
秒之后,它肯定不会启动,对吗?
此外,如果我将 concurrencyPolicy
设置为 Forbid
,如果尝试安排一个 cronjob,K8s 是否将其视为失败,而此时已经 运行?
调查 Kubernetes repo 的代码库后,CronJob 控制器的工作原理如下:
CronJob 控制器 will check the every 10 seconds 给定 Kubernetes 客户端中的 cronjobs 列表。
对于每个 CronJob,它会检查从
lastScheduleTime
到现在的持续时间内错过了多少计划。如果超过 100 missed schedules,则不会启动作业并记录事件:"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
秒内发生了多少个错过的作业。具体实现统计错过多少可以找到here.
如果上一步错过的计划不超过 100 个,CronJob 控制器将检查时间
now
是否在其 [=19= 的时间之后],即现在开始工作还为时不晚(超过了截止日期)。如果还不算太晚,CronJob 控制器将继续尝试启动该作业。但是,如果为时已晚,则不会启动作业并记录事件:"Missed starting window for {cronjob name}. Missed scheduled time to start a job {scheduledTime}"
另外重要 需要注意的是,如果字段 startingDeadlineSeconds
未设置,则意味着根本没有截止日期。这意味着 CronJob 控制器将尝试启动该作业,而不检查它是否晚了。
因此回答以上问题:
1.如果 startingDeadlineSeconds 设置为 10 并且 cronjob 由于某种原因无法在预定时间启动,那么只要这 10 秒没有过去,它仍然可以尝试再次启动,但是,在 10 秒之后,它肯定不会启动,这是正确的吗?
CronJob 控制器将尝试启动作业,如果在计划时间后的 10 秒还没有过去,它将成功计划。但是,如果已经过了deadline,则不会在本次运行开始执行,在后面的执行中会被算作错过了。
2。如果我将 concurrencyPolicy 设置为 Forbid,如果一个 cronjob 试图被安排,K8s 是否将其视为失败,而此时已经有一个 运行ning?
是的,这将被计为错过日程。由于错过的时间表是按照我上面第 2 点所述计算的。