@@ -20,7 +20,7 @@ Unix system. It runs a job periodically on a given schedule, written in
20
20
[ Cron] ( https://en.wikipedia.org/wiki/Cron ) format.
21
21
22
22
CronJobs have limitations and idiosyncrasies.
23
- For example, in certain circumstances, a single cron job can create multiple jobs . See the [ limitations] ( #cron-job-limitations ) below.
23
+ For example, in certain circumstances, a single CronJob can create multiple concurrent Jobs . See the [ limitations] ( #cron-job-limitations ) below.
24
24
25
25
When the control plane creates new Jobs and (indirectly) Pods for a CronJob, the ` .metadata.name `
26
26
of the CronJob is part of the basis for naming those Pods. The name of a CronJob must be a valid
@@ -44,8 +44,8 @@ This example CronJob manifest prints the current time and a hello message every
44
44
takes you through this example in more detail).
45
45
46
46
## Writing a CronJob spec
47
- ### Schedule
48
- The ` .spec.schedule ` is a required field and follows the [ Cron] ( https://en.wikipedia.org/wiki/Cron ) syntax below :
47
+ ### Schedule syntax
48
+ The ` .spec.schedule ` field is required. The value of that field follows the [ Cron] ( https://en.wikipedia.org/wiki/Cron ) syntax:
49
49
50
50
```
51
51
# ┌───────────── minute (0 - 59)
@@ -88,20 +88,29 @@ Other than the standard syntax, some macros like `@monthly` can also be used:
88
88
89
89
To generate CronJob schedule expressions, you can also use web tools like [ crontab.guru] ( https://crontab.guru/ ) .
90
90
91
- ### Job Template
91
+ ### Job template
92
92
93
- The ` .spec.jobTemplate ` is the template for the job , and it is required.
93
+ The ` .spec.jobTemplate ` defines a template for the Jobs that the CronJob creates , and it is required.
94
94
It has exactly the same schema as a [ Job] ( /docs/concepts/workloads/controllers/job/ ) , except that
95
95
it is nested and does not have an ` apiVersion ` or ` kind ` .
96
- For information about writing a job ` .spec ` , see [ Writing a Job Spec] ( /docs/concepts/workloads/controllers/job/#writing-a-job-spec ) .
96
+ You can specify common metadata for the templated Jobs, such as
97
+ {{< glossary_tooltip text="labels" term_id="label" >}} or
98
+ {{< glossary_tooltip text="annotations" term_id="annotation" >}}.
99
+ For information about writing a Job ` .spec ` , see [ Writing a Job Spec] ( /docs/concepts/workloads/controllers/job/#writing-a-job-spec ) .
97
100
98
- ### Starting Deadline
101
+ ### Deadline for delayed job start {#starting-deadline}
99
102
100
103
The ` .spec.startingDeadlineSeconds ` field is optional.
101
- It stands for the deadline in seconds for starting the job if it misses its scheduled time for any reason.
102
- After the deadline, the CronJob does not start the job.
103
- Jobs that do not meet their deadline in this way count as failed jobs.
104
- If this field is not specified, the jobs have no deadline.
104
+ This field defines a deadline (in whole seconds) for starting the Job, if that Job misses its scheduled time
105
+ for any reason.
106
+
107
+ After missing the deadline, the CronJob skips that instance of the Job (future occurrences are still scheduled).
108
+ For example, if you have a backup job that runs twice a day, you might allow it to start up to 8 hours late,
109
+ but no later, because a backup taken any later wouldn't be useful: you would instead prefer to wait for
110
+ the next scheduled run.
111
+
112
+ For Jobs that miss their configured deadline, Kubernetes treats them as failed Jobs.
113
+ If you don't specify ` startingDeadlineSeconds ` for a CronJob, the Job occurrences have no deadline.
105
114
106
115
If the ` .spec.startingDeadlineSeconds ` field is set (not null), the CronJob
107
116
controller measures the time between when a job is expected to be created and
@@ -110,7 +119,7 @@ now. If the difference is higher than that limit, it will skip this execution.
110
119
For example, if it is set to ` 200 ` , it allows a job to be created for up to 200
111
120
seconds after the actual schedule.
112
121
113
- ### Concurrency Policy
122
+ ### Concurrency policy
114
123
115
124
The ` .spec.concurrencyPolicy ` field is also optional.
116
125
It specifies how to treat concurrent executions of a job that is created by this CronJob.
@@ -125,20 +134,24 @@ The spec may specify only one of the following concurrency policies:
125
134
Note that concurrency policy only applies to the jobs created by the same cron job.
126
135
If there are multiple CronJobs, their respective jobs are always allowed to run concurrently.
127
136
128
- ### Suspend
137
+ ### Schedule suspension
138
+
139
+ You can suspend execution of Jobs for a CronJob, by setting the optional ` .spec.suspend ` field
140
+ to true. The field defaults to false.
141
+
142
+ This setting does _ not_ affect Jobs that the CronJob has already started.
129
143
130
- The ` .spec.suspend ` field is also optional.
131
- If it is set to ` true ` , all subsequent executions are suspended.
132
- This setting does not apply to already started executions.
133
- Defaults to false.
144
+ If you do set that field to true, all subsequent executions are suspended (they remain
145
+ scheduled, but the CronJob controller does not start the Jobs to run the tasks) until
146
+ you unsuspend the CronJob.
134
147
135
148
{{< caution >}}
136
149
Executions that are suspended during their scheduled time count as missed jobs.
137
150
When ` .spec.suspend ` changes from ` true ` to ` false ` on an existing CronJob without a
138
151
[ starting deadline] ( #starting-deadline ) , the missed jobs are scheduled immediately.
139
152
{{< /caution >}}
140
153
141
- ### Jobs History Limits
154
+ ### Jobs history limits
142
155
143
156
The ` .spec.successfulJobsHistoryLimit ` and ` .spec.failedJobsHistoryLimit ` fields are optional.
144
157
These fields specify how many completed and failed jobs should be kept.
@@ -178,15 +191,19 @@ A time zone database from the Go standard library is included in the binaries an
178
191
## CronJob limitations {#cron-job-limitations}
179
192
180
193
### Modifying a CronJob
181
- If you modify a CronJob, the changes you make will apply to new jobs that start to run after your modification
182
- is complete. Jobs (and their Pods) that have already started continue to run without changes.
183
- That is, the CronJob does _ not_ update existing jobs, even if those remain running.
194
+ By design, a CronJob contains a template for _ new_ Jobs.
195
+ If you modify an existing CronJob, the changes you make will apply to new Jobs that
196
+ start to run after your modification is complete. Jobs (and their Pods) that have already
197
+ started continue to run without changes.
198
+ That is, the CronJob does _ not_ update existing Jobs, even if those remain running.
184
199
185
200
### Job creation
186
201
187
- A CronJob creates a job object _ about_ once per execution time of its schedule. We say "about" because there
188
- are certain circumstances where two jobs might be created, or no job might be created. We attempt to make these rare,
189
- but do not completely prevent them. Therefore, jobs should be _ idempotent_ .
202
+ A CronJob creates a Job object approximately once per execution time of its schedule.
203
+ The scheduling is approximate because there
204
+ are certain circumstances where two Jobs might be created, or no Job might be created.
205
+ Kubernetes tries to avoid those situations, but do not completely prevent them. Therefore,
206
+ the Jobs that you define should be _ idempotent_ .
190
207
191
208
If ` startingDeadlineSeconds ` is set to a large value or left unset (the default)
192
209
and if ` concurrencyPolicy ` is set to ` Allow ` , the jobs will always run
@@ -230,4 +247,4 @@ the Job in turn is responsible for the management of the Pods it represents.
230
247
see [ Running automated tasks with CronJobs] ( /docs/tasks/job/automated-tasks-with-cron-jobs/ ) .
231
248
* ` CronJob ` is part of the Kubernetes REST API.
232
249
Read the {{< api-reference page="workload-resources/cron-job-v1" >}}
233
- reference doc for more details.
250
+ API reference for more details.
0 commit comments