35-cronJob

cucytoman發表於2019-10-29

concepts/workloads/controllers/cron-jobs/

A Cron Job creates Jobs on a time-based schedule. cron job按基於時間的計劃建立作業

One CronJob object is like one line of a crontab (cron table) file. It runs a job periodically on a given schedule, written in Cron format. 一個cronjob物件就像crontab(cron table)檔案的一行。它按照給定的時間表定期執行作業,以cron格式編寫

Note: All CronJob schedule: times are based on the timezone of the master where the job is initiated.

For instructions on creating and working with cron jobs, and for an example of a spec file for a cron job, see Running automated tasks with cron jobs. 有關建立和使用cron作業的說明,以及cron作業的spec檔案示例,請參見

Cron Job Limitations

A cron job creates a job object about once per execution time of its schedule. We say “about” because there are certain circumstances where two jobs might be created, or no job might be created. We attempt to make these rare, but do not completely prevent them. Therefore, jobs should be idempotent. cron作業在其計劃的每個執行時間建立一個作業物件大約一次。我們之所以說“關於”,是因為在某些情況下,可能會創造兩個工作崗位,也可能不會創造任何工作崗位。我們試圖使這些罕見,但並不完全阻止他們。因此,作業應該是等冪

If startingDeadlineSeconds is set to a large value or left unset (the default) and if concurrencyPolicy is set to Allow, the jobs will always run at least once. 如果“startingdeadlineseconds”設定為大值或未設定(預設值),並且“concurrency policy”設定為“allow”,則作業將始終至少執行一次。

For every CronJob, the CronJob Controller checks how many schedules it missed in the duration from its last scheduled time until now. If there are more than 100 missed schedules, then it does not start the job and logs the error 對於每個cronjob,cronjob控制器檢查從上次計劃時間到現在的持續時間內它錯過了多少計劃。如果錯過的計劃超過100個,則它不會啟動作業並記錄錯誤

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

It is important to note that if the startingDeadlineSeconds field is set (not nil), the controller counts how many missed jobs occurred from the value of startingDeadlineSeconds until now rather than from the last scheduled time until now. For example, if startingDeadlineSeconds is 200, the controller counts how many missed jobs occurred in the last 200 seconds. 需要注意的是,如果設定了“startingdeadlineseconds”欄位(而不是“nil”),則控制器將從“startingdeadlineseconds”的值到現在(而不是從上次計劃的時間到現在)統計錯過的作業數。例如,如果“startingdeadlineseconds”為“200”,則控制器將統計過去200秒內發生的未命中作業數。

A CronJob is counted as missed if it has failed to be created at its scheduled time. For example, If concurrencyPolicy is set to Forbid and a CronJob was attempted to be scheduled when there was a previous schedule still running, then it would count as missed. 如果未能在計劃時間建立cronjob,則該cronjob將被計為未命中。例如,如果將“concurrency policy”設定為“forbid”,並且在前一個計劃仍在執行時試圖排程cronjob,則該cronjob將被計為missed。

For example, suppose a CronJob is set to schedule a new Job every one minute beginning at 08:30:00, and its startingDeadlineSeconds field is not set. If the CronJob controller happens to be down from 08:29:00 to 10:21:00, the job will not start as the number of missed jobs which missed their schedule is greater than 100. 例如,假設一個cronjob設定為從“08:30:00”開始每分鐘排程一個新作業,而其“startingdeadlineseconds”欄位未設定。如果cronjob控制器恰好從“08:29:00”降至“10:21:00”,則由於錯過計劃的錯過作業數大於100,作業將不會啟動。

To illustrate this concept further, suppose a CronJob is set to schedule a new Job every one minute beginning at 08:30:00, and its startingDeadlineSeconds is set to 200 seconds. If the CronJob controller happens to be down for the same period as the previous example (08:29:00 to 10:21:00,) the Job will still start at 10:22:00. This happens as the controller now checks how many missed schedules happened in the last 200 seconds (ie, 3 missed schedules), rather than from the last scheduled time until now. 為了進一步說明這個概念,假設一個cronjob被設定為從“08:30:00”開始每一分鐘排程一個新作業,並且它的“startingdeadlineseconds”被設定為200秒。如果cronjob控制器恰巧在與前面的示例相同的時間段內關閉(08:29:00到`10:21:00',),則作業仍將在10:22:00開始。這是因為控制器現在檢查在過去200秒內發生了多少個錯過的計劃(即,3個錯過的計劃),而不是從上一個計劃時間到現在。

The CronJob is only responsible for creating Jobs that match its schedule, and the Job in turn is responsible for the management of the Pods it represents. cronjob只負責建立與其計劃相匹配的作業,而作業則負責管理它所代表的pod。

Feedback

Was this page helpful?

本作品採用《CC 協議》,轉載必須註明作者和本文連結