You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A _CronJob_ creates {{< glossary_tooltip term_id="job" text="Jobs" >}} on a repeating schedule.
16
16
17
-
One CronJob object is like one line of a _crontab_ (cron table) file. It runs a job periodically
18
-
on a given schedule, written in [Cron](https://en.wikipedia.org/wiki/Cron) format.
17
+
One CronJob object is like one line of a _crontab_ (cron table) file on a Unix system. It runs a job periodically on a given schedule, written in [Cron](https://en.wikipedia.org/wiki/Cron) format.
19
18
20
-
{{< caution >}}
21
-
All **CronJob**`schedule:` times are based on the timezone of the
If your control plane runs the kube-controller-manager in Pods or bare
104
+
containers, the timezone set for the kube-controller-manager container determines the timezone
105
+
that the CronJob controller uses.
106
+
{{< /caution >}}
92
107
93
-
For example, the line below states that the task must be started every Friday at midnight, as well as on the 13th of each month at midnight:
108
+
{{< caution >}}
109
+
The [v1 CronJob API](/docs/reference/kubernetes-api/workload-resources/cron-job-v1/)
110
+
does not officially support setting timezone as explained above.
94
111
95
-
`0 0 13 * 5`
112
+
Setting variables such as `CRON_TZ` or `TZ` is not officially supported by the Kubernetes project.
113
+
`CRON_TZ` or `TZ` is an implementation detail of the internal library being used
114
+
for parsing and calculating the next Job creation time. Any usage of it is not
115
+
recommended in a production cluster.
116
+
{{< /caution >}}
96
117
97
118
To generate CronJob schedule expressions, you can also use web tools like [crontab.guru](https://crontab.guru/).
98
119
120
+
### Job Template
121
+
122
+
The `.spec.jobTemplate` is the template for the job, and it is required.
123
+
It has exactly the same schema as a [Job](/docs/concepts/workloads/controllers/job/), except that
124
+
it is nested and does not have an `apiVersion` or `kind`.
125
+
For information about writing a job `.spec`, see [Writing a Job Spec](/docs/concepts/workloads/controllers/job/#writing-a-job-spec).
126
+
127
+
### Starting Deadline
128
+
129
+
The `.spec.startingDeadlineSeconds` field is optional.
130
+
It stands for the deadline in seconds for starting the job if it misses its scheduled time for any reason.
131
+
After the deadline, the CronJob does not start the job.
132
+
Jobs that do not meet their deadline in this way count as failed jobs.
133
+
If this field is not specified, the jobs have no deadline.
134
+
135
+
If the `.spec.startingDeadlineSeconds` field is set (not null), the CronJob
136
+
controller measures the time between when a job is expected to be created and
137
+
now. If the difference is higher than that limit, it will skip this execution.
138
+
139
+
For example, if it is set to `200`, it allows a job to be created for up to 200
140
+
seconds after the actual schedule.
141
+
142
+
### Concurrency Policy
143
+
144
+
The `.spec.concurrencyPolicy` field is also optional.
145
+
It specifies how to treat concurrent executions of a job that is created by this CronJob.
146
+
The spec may specify only one of the following concurrency policies:
147
+
148
+
*`Allow` (default): The CronJob allows concurrently running jobs
149
+
*`Forbid`: The CronJob does not allow concurrent runs; if it is time for a new job run and the
150
+
previous job run hasn't finished yet, the CronJob skips the new job run
151
+
*`Replace`: If it is time for a new job run and the previous job run hasn't finished yet, the
152
+
CronJob replaces the currently running job run with a new job run
153
+
154
+
Note that concurrency policy only applies to the jobs created by the same cron job.
155
+
If there are multiple CronJobs, their respective jobs are always allowed to run concurrently.
156
+
157
+
### Suspend
158
+
159
+
The `.spec.suspend` field is also optional.
160
+
If it is set to `true`, all subsequent executions are suspended.
161
+
This setting does not apply to already started executions.
162
+
Defaults to false.
163
+
164
+
{{< caution >}}
165
+
Executions that are suspended during their scheduled time count as missed jobs.
166
+
When `.spec.suspend` changes from `true` to `false` on an existing CronJob without a
167
+
[starting deadline](#starting-deadline), the missed jobs are scheduled immediately.
168
+
{{< /caution >}}
169
+
170
+
### Jobs History Limits
171
+
172
+
The `.spec.successfulJobsHistoryLimit` and `.spec.failedJobsHistoryLimit` fields are optional.
173
+
These fields specify how many completed and failed jobs should be kept.
174
+
By default, they are set to 3 and 1 respectively. Setting a limit to `0` corresponds to keeping
175
+
none of the corresponding kind of jobs after they finish.
176
+
177
+
For another way to clean up jobs automatically, see [Clean up finished jobs automatically](/docs/concepts/workloads/controllers/job/#clean-up-finished-jobs-automatically).
178
+
99
179
## Time zones
100
180
101
181
For CronJobs with no time zone specified, the kube-controller-manager interprets schedules relative to its local time zone.
@@ -107,14 +187,14 @@ you can specify a time zone for a CronJob (if you don't enable that feature gate
107
187
Kubernetes that does not have experimental time zone support, all CronJobs in your cluster have an unspecified
108
188
timezone).
109
189
110
-
When you have the feature enabled, you can set `spec.timeZone` to the name of a valid [time zone](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones). For example, setting
111
-
`spec.timeZone: "Etc/UTC"` instructs Kubernetes to interpret the schedule relative to Coordinated Universal Time.
190
+
When you have the feature enabled, you can set `.spec.timeZone` to the name of a valid [time zone](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones). For example, setting
191
+
`.spec.timeZone: "Etc/UTC"` instructs Kubernetes to interpret the schedule relative to Coordinated Universal Time.
112
192
113
193
A time zone database from the Go standard library is included in the binaries and used as a fallback in case an external database is not available on the system.
114
194
115
195
## CronJob limitations {#cron-job-limitations}
116
196
117
-
A cron job creates a job object _about_ once per execution time of its schedule. We say "about" because there
197
+
A CronJob creates a job object _about_ once per execution time of its schedule. We say "about" because there
118
198
are certain circumstances where two jobs might be created, or no job might be created. We attempt to make these rare,
119
199
but do not completely prevent them. Therefore, jobs should be _idempotent_.
120
200
@@ -167,13 +247,11 @@ and set this flag to `false`. For example:
167
247
* Learn about [Pods](/docs/concepts/workloads/pods/) and
168
248
[Jobs](/docs/concepts/workloads/controllers/job/), two concepts
169
249
that CronJobs rely upon.
170
-
* Read about the [format](https://pkg.go.dev/github.com/robfig/cron/v3#hdr-CRON_Expression_Format)
250
+
* Read about the detailed [format](https://pkg.go.dev/github.com/robfig/cron/v3#hdr-CRON_Expression_Format)
171
251
of CronJob `.spec.schedule` fields.
172
252
* For instructions on creating and working with CronJobs, and for an example
173
253
of a CronJob manifest,
174
254
see [Running automated tasks with CronJobs](/docs/tasks/job/automated-tasks-with-cron-jobs/).
175
-
* For instructions to clean up failed or completed jobs automatically,
176
-
see [Clean up Jobs automatically](/docs/concepts/workloads/controllers/job/#clean-up-finished-jobs-automatically)
177
255
*`CronJob` is part of the Kubernetes REST API.
178
256
Read the {{< api-reference page="workload-resources/cron-job-v1" >}}
179
-
object definition to understand the API for Kubernetes cron jobs.
0 commit comments