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
Copy file name to clipboardExpand all lines: content/en/docs/concepts/workloads/controllers/cron-jobs.md
+19-22Lines changed: 19 additions & 22 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -14,9 +14,9 @@ weight: 80
14
14
15
15
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 on a Unix system. It runs a job periodically on a given schedule, written in [Cron](https://en.wikipedia.org/wiki/Cron) format.
17
+
CronJob is meant for performing regular scheduled actions such as backups, report generation, and so on. 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.
18
18
19
-
Cron jobs have limitations and idiosyncrasies.
19
+
CronJobs have limitations and idiosyncrasies.
20
20
For example, in certain circumstances, a single cron job can create multiple jobs. See the [limitations](#cron-job-limitations) below.
21
21
22
22
When the control plane creates new Jobs and (indirectly) Pods for a CronJob, the `.metadata.name`
@@ -31,21 +31,7 @@ characters. This is because the CronJob controller will automatically append
31
31
length of a Job name is no more than 63 characters.
32
32
33
33
<!-- body -->
34
-
35
-
## CronJob
36
-
37
-
CronJobs are meant for performing regular scheduled actions such as backups,
38
-
report generation, and so on. Each of those tasks should be configured to recur
39
-
indefinitely (for example: once a day / week / month); you can define the point
40
-
in time within that interval when the job should start.
41
-
42
-
{{< note >}}
43
-
If you modify a CronJob, the changes you make will apply to new jobs that start to run after your modification
44
-
is complete. Jobs (and their Pods) that have already started continue to run without changes.
45
-
That is, the CronJob does _not_ update existing jobs, even if those remain running.
46
-
{{< /note >}}
47
-
48
-
### Example
34
+
## Example
49
35
50
36
This example CronJob manifest prints the current time and a hello message every minute:
51
37
@@ -54,6 +40,7 @@ This example CronJob manifest prints the current time and a hello message every
54
40
([Running Automated Tasks with a CronJob](/docs/tasks/job/automated-tasks-with-cron-jobs/)
55
41
takes you through this example in more detail).
56
42
43
+
## Writing a CronJob spec
57
44
### Schedule
58
45
The `.spec.schedule` is a required field and follows the [Cron](https://en.wikipedia.org/wiki/Cron) syntax below:
59
46
@@ -96,10 +83,6 @@ Other than the standard syntax, some macros like `@monthly` can also be used:
96
83
|@daily (or @midnight) | Run once a day at midnight | 0 0 * * * |
97
84
|@hourly| Run once an hour at the beginning of the hour | 0 * * * * |
98
85
99
-
{{< caution >}}
100
-
Historically you may find the `.spec.schedule` field can be set with a timezone like `CRON_TZ=UTC * * * * *`. This way is not recommended any more and you should consider use the `.spec.timeZone` field as described below.
101
-
{{< /caution >}}
102
-
103
86
To generate CronJob schedule expressions, you can also use web tools like [crontab.guru](https://crontab.guru/).
104
87
105
88
### Job Template
@@ -161,7 +144,7 @@ none of the corresponding kind of jobs after they finish.
161
144
162
145
For another way to clean up jobs automatically, see [Clean up finished jobs automatically](/docs/concepts/workloads/controllers/job/#clean-up-finished-jobs-automatically).
163
146
164
-
## Time zones
147
+
###Time zones
165
148
166
149
For CronJobs with no time zone specified, the kube-controller-manager interprets schedules relative to its local time zone.
167
150
@@ -175,10 +158,24 @@ timezone).
175
158
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
176
159
`.spec.timeZone: "Etc/UTC"` instructs Kubernetes to interpret the schedule relative to Coordinated Universal Time.
177
160
161
+
{{< caution >}}
162
+
Historically you may find the `.spec.schedule` field can be set with a timezone like `CRON_TZ=UTC * * * * *` or `TZ=UTC * * * * *`. This way is not recommended any more and you should consider use the `.spec.timeZone` field as described above.
163
+
{{< /caution >}}
164
+
178
165
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.
179
166
180
167
## CronJob limitations {#cron-job-limitations}
181
168
169
+
### Name limitations
170
+
When creating the manifest for a CronJob resource, make sure the name you provide is a valid DNS subdomain name. The name must be no longer than 52 characters. This is because the CronJob controller will automatically append 11 characters to the job name provided and there is a constraint that the maximum length of a Job name is no more than 63 characters.
171
+
172
+
### Modifying a CronJob
173
+
If you modify a CronJob, the changes you make will apply to new jobs that start to run after your modification
174
+
is complete. Jobs (and their Pods) that have already started continue to run without changes.
175
+
That is, the CronJob does _not_ update existing jobs, even if those remain running.
176
+
177
+
### How a CronJob schedules
178
+
182
179
A CronJob creates a job object _about_ once per execution time of its schedule. We say "about" because there
183
180
are certain circumstances where two jobs might be created, or no job might be created. We attempt to make these rare,
184
181
but do not completely prevent them. Therefore, jobs should be _idempotent_.
0 commit comments