Skip to content

Commit b3f2453

Browse files
authored
Merge pull request #34465 from windsonsea/docsite3
[en] discussions about automated-tasks-with-cron-jobs.md
2 parents 5ae09a9 + 3e51d19 commit b3f2453

File tree

1 file changed

+20
-22
lines changed

1 file changed

+20
-22
lines changed

content/en/docs/tasks/job/automated-tasks-with-cron-jobs.md

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,16 @@ Therefore, jobs should be idempotent.
2626

2727
For more limitations, see [CronJobs](/docs/concepts/workloads/controllers/cron-jobs).
2828

29-
30-
3129
## {{% heading "prerequisites" %}}
3230

33-
3431
* {{< include "task-tutorial-prereqs.md" >}}
3532

36-
37-
3833
<!-- steps -->
3934

40-
## Creating a Cron Job
35+
## Creating a CronJob {#creating-a-cron-job}
4136

4237
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:
4439

4540
{{< codenew file="application/job/cronjob.yaml" >}}
4641

@@ -60,6 +55,7 @@ After creating the cron job, get its status using this command:
6055
```shell
6156
kubectl get cronjob hello
6257
```
58+
6359
The output is similar to this:
6460

6561
```
@@ -102,14 +98,14 @@ You should see that the cron job `hello` successfully scheduled a job at the tim
10298
Now, find the pods that the last scheduled job created and view the standard output of one of the pods.
10399

104100
{{< note >}}
105-
The job name and pod name are different.
101+
The job name is different from the pod name.
106102
{{< /note >}}
107103

108104
```shell
109105
# Replace "hello-4111706356" with the job name in your system
110106
pods=$(kubectl get pods --selector=job-name=hello-4111706356 --output=jsonpath={.items[*].metadata.name})
111107
```
112-
Show pod log:
108+
Show the pod log:
113109

114110
```shell
115111
kubectl logs $pods
@@ -121,7 +117,7 @@ Fri Feb 22 11:02:09 UTC 2019
121117
Hello from the Kubernetes cluster
122118
```
123119

124-
## Deleting a Cron Job
120+
## Deleting a CronJob {#deleting-a-cron-job}
125121

126122
When you don't need a cron job any more, delete it with `kubectl delete cronjob <cronjob name>`:
127123

@@ -132,16 +128,20 @@ kubectl delete cronjob hello
132128
Deleting the cron job removes all the jobs and pods it created and stops it from creating additional jobs.
133129
You can read more about removing jobs in [garbage collection](/docs/concepts/architecture/garbage-collection/).
134130

135-
## Writing a Cron Job Spec
131+
## Writing a CronJob Spec {#writing-a-cron-job-spec}
136132

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/),
139137
and [using kubectl to manage resources](/docs/concepts/overview/working-with-objects/object-management/) documents.
140138

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.
142140

143141
{{< 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.
145145
{{< /note >}}
146146

147147
### Schedule
@@ -153,11 +153,11 @@ as schedule time of its jobs to be created and executed.
153153
The format also includes extended "Vixie cron" step values. As explained in the
154154
[FreeBSD manual](https://www.freebsd.org/cgi/man.cgi?crontab%285%29):
155155

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
161161
> asterisk, so if you want to say "every two hours", just use `*/2`.
162162
163163
{{< note >}}
@@ -221,5 +221,3 @@ The `.spec.successfulJobsHistoryLimit` and `.spec.failedJobsHistoryLimit` fields
221221
These fields specify how many completed and failed jobs should be kept.
222222
By default, they are set to 3 and 1 respectively. Setting a limit to `0` corresponds to keeping
223223
none of the corresponding kind of jobs after they finish.
224-
225-

0 commit comments

Comments
 (0)