@@ -26,21 +26,16 @@ Therefore, jobs should be idempotent.
26
26
27
27
For more limitations, see [ CronJobs] ( /docs/concepts/workloads/controllers/cron-jobs ) .
28
28
29
-
30
-
31
29
## {{% heading "prerequisites" %}}
32
30
33
-
34
31
* {{< include "task-tutorial-prereqs.md" >}}
35
32
36
-
37
-
38
33
<!-- steps -->
39
34
40
- ## Creating a Cron Job
35
+ ## Creating a CronJob {#creating-a-cron-job}
41
36
42
37
Cron jobs require a config file.
43
- This example cron job config ` .spec ` file prints the current time and a hello message every minute:
38
+ Here is a manifest for a CronJob that runs a simple demonstration task every minute:
44
39
45
40
{{< codenew file="application/job/cronjob.yaml" >}}
46
41
@@ -60,6 +55,7 @@ After creating the cron job, get its status using this command:
60
55
``` shell
61
56
kubectl get cronjob hello
62
57
```
58
+
63
59
The output is similar to this:
64
60
65
61
```
@@ -102,14 +98,14 @@ You should see that the cron job `hello` successfully scheduled a job at the tim
102
98
Now, find the pods that the last scheduled job created and view the standard output of one of the pods.
103
99
104
100
{{< note >}}
105
- The job name and pod name are different .
101
+ The job name is different from the pod name .
106
102
{{< /note >}}
107
103
108
104
``` shell
109
105
# Replace "hello-4111706356" with the job name in your system
110
106
pods=$( kubectl get pods --selector=job-name=hello-4111706356 --output=jsonpath={.items[* ].metadata.name})
111
107
```
112
- Show pod log:
108
+ Show the pod log:
113
109
114
110
``` shell
115
111
kubectl logs $pods
@@ -121,7 +117,7 @@ Fri Feb 22 11:02:09 UTC 2019
121
117
Hello from the Kubernetes cluster
122
118
```
123
119
124
- ## Deleting a Cron Job
120
+ ## Deleting a CronJob {#deleting-a-cron-job}
125
121
126
122
When you don't need a cron job any more, delete it with ` kubectl delete cronjob <cronjob name> ` :
127
123
@@ -132,16 +128,20 @@ kubectl delete cronjob hello
132
128
Deleting the cron job removes all the jobs and pods it created and stops it from creating additional jobs.
133
129
You can read more about removing jobs in [ garbage collection] ( /docs/concepts/architecture/garbage-collection/ ) .
134
130
135
- ## Writing a Cron Job Spec
131
+ ## Writing a CronJob Spec {#writing-a-cron-job-spec}
136
132
137
- As with all other Kubernetes configs, a cron job needs ` apiVersion ` , ` kind ` , and ` metadata ` fields. For general
138
- information about working with config files, see [ deploying applications] ( /docs/tasks/run-application/run-stateless-application-deployment/ ) ,
133
+ As with all other Kubernetes objects, a CronJob must have ` apiVersion ` , ` kind ` , and ` metadata ` fields.
134
+ For more information about working with Kubernetes objects and their
135
+ {{< glossary_tooltip text="manifests" term_id="manifest" >}}, see the
136
+ [ managing resources] ( /docs/concepts/cluster-administration/manage-deployment/ ) ,
139
137
and [ using kubectl to manage resources] ( /docs/concepts/overview/working-with-objects/object-management/ ) documents.
140
138
141
- A cron job config also needs a [ ` .spec ` section ] ( https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md# spec-and-status) .
139
+ Each manifest for a CrobJob also needs a [ ` .spec ` ] ( /docs/concepts/overview/working-with-objects/kubernetes-objects/#object- spec-and-status) section .
142
140
143
141
{{< note >}}
144
- All modifications to a cron job, especially its ` .spec ` , are applied only to the following runs.
142
+ If you modify a CronJob, the changes you make will apply to new jobs that start to run after your modification
143
+ is complete. Jobs (and their Pods) that have already started continue to run without changes.
144
+ That is, the CronJob does _ not_ update existing jobs, even if those remain running.
145
145
{{< /note >}}
146
146
147
147
### Schedule
@@ -153,11 +153,11 @@ as schedule time of its jobs to be created and executed.
153
153
The format also includes extended "Vixie cron" step values. As explained in the
154
154
[ FreeBSD manual] ( https://www.freebsd.org/cgi/man.cgi?crontab%285%29 ) :
155
155
156
- > Step values can be used in conjunction with ranges. Following a range
157
- > with ` /<number> ` specifies skips of the number's value through the
158
- > range. For example, ` 0-23/2 ` can be used in the hours field to specify
159
- > command execution every other hour (the alternative in the V7 standard is
160
- > ` 0,2,4,6,8,10,12,14,16,18,20,22 ` ). Steps are also permitted after an
156
+ > Step values can be used in conjunction with ranges. Following a range
157
+ > with ` /<number> ` specifies skips of the number's value through the
158
+ > range. For example, ` 0-23/2 ` can be used in the hours field to specify
159
+ > command execution every other hour (the alternative in the V7 standard is
160
+ > ` 0,2,4,6,8,10,12,14,16,18,20,22 ` ). Steps are also permitted after an
161
161
> asterisk, so if you want to say "every two hours", just use ` */2 ` .
162
162
163
163
{{< note >}}
@@ -221,5 +221,3 @@ The `.spec.successfulJobsHistoryLimit` and `.spec.failedJobsHistoryLimit` fields
221
221
These fields specify how many completed and failed jobs should be kept.
222
222
By default, they are set to 3 and 1 respectively. Setting a limit to ` 0 ` corresponds to keeping
223
223
none of the corresponding kind of jobs after they finish.
224
-
225
-
0 commit comments