Skip to content

Commit e293ca7

Browse files
committed
[zh] sync /controllers/cron-jobs.md
1 parent 8af413f commit e293ca7

File tree

1 file changed

+33
-35
lines changed
  • content/zh-cn/docs/concepts/workloads/controllers

1 file changed

+33
-35
lines changed

content/zh-cn/docs/concepts/workloads/controllers/cron-jobs.md

Lines changed: 33 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ weight: 80
55
---
66

77
<!--
8+
reviewers:
9+
- erictune
10+
- soltysh
11+
- janetkuo
812
title: CronJob
913
content_type: concept
1014
weight: 80
@@ -20,29 +24,29 @@ A _CronJob_ creates {{< glossary_tooltip term_id="job" text="Jobs" >}} on a repe
2024
One CronJob object is like one line of a _crontab_ (cron table) file. It runs a job periodically
2125
on a given schedule, written in [Cron](https://en.wikipedia.org/wiki/Cron) format.
2226
-->
23-
_CronJob_ 创建基于时隔重复调度的 {{< glossary_tooltip term_id="job" text="Jobs" >}}。
27+
**CronJob** 创建基于时隔重复调度的 {{< glossary_tooltip term_id="job" text="Job" >}}。
2428

25-
一个 CronJob 对象就像 _crontab_ (cron table) 文件中的一行。
29+
一个 CronJob 对象就像 **crontab** (cron table) 文件中的一行。
2630
它用 [Cron](https://en.wikipedia.org/wiki/Cron) 格式进行编写,
2731
并周期性地在给定的调度时间执行 Job。
2832

33+
{{< caution >}}
2934
<!--
3035
All **CronJob** `schedule:` times are based on the timezone of the
3136
3237
If your control plane runs the kube-controller-manager in Pods or bare
3338
containers, the timezone set for the kube-controller-manager container determines the timezone
3439
that the cron job controller uses.
3540
-->
36-
37-
{{< caution >}}
3841
所有 **CronJob**`schedule:` 时间都是基于
39-
{{< glossary_tooltip term_id="kube-controller-manager" text="kube-controller-manager" >}}.
42+
{{< glossary_tooltip term_id="kube-controller-manager" text="kube-controller-manager" >}}
4043
的时区。
4144

4245
如果你的控制平面在 Pod 或是裸容器中运行了 kube-controller-manager,
4346
那么为该容器所设置的时区将会决定 Cron Job 的控制器所使用的时区。
4447
{{< /caution >}}
4548

49+
{{< caution >}}
4650
<!--
4751
The [v1 CronJob API](/docs/reference/kubernetes-api/workload-resources/cron-job-v1/)
4852
does not officially support setting timezone as explained above.
@@ -52,8 +56,6 @@ Setting variables such as `CRON_TZ` or `TZ` is not officially supported by the K
5256
for parsing and calculating the next Job creation time. Any usage of it is not
5357
recommended in a production cluster.
5458
-->
55-
56-
{{< caution >}}
5759
[v1 CronJob API](/zh-cn/docs/reference/kubernetes-api/workload-resources/cron-job-v1/) 所述,官方并不支持设置时区。
5860

5961
Kubernetes 项目官方并不支持设置如 `CRON_TZ` 或者 `TZ` 等变量。
@@ -101,8 +103,7 @@ This example CronJob manifest prints the current time and a hello message every
101103

102104
{{< codenew file="application/job/cronjob.yaml" >}}
103105

104-
[使用 CronJob 运行自动化任务](/zh-cn/docs/tasks/job/automated-tasks-with-cron-jobs/)
105-
一文会为你详细讲解此例。
106+
[使用 CronJob 运行自动化任务](/zh-cn/docs/tasks/job/automated-tasks-with-cron-jobs/)一文会为你详细讲解此例。
106107

107108
<!--
108109
### Cron schedule syntax
@@ -132,10 +133,10 @@ This example CronJob manifest prints the current time and a hello message every
132133
-->
133134
| 输入 | 描述 | 相当于 |
134135
| ------------- | ------------- |------------- |
135-
| @yearly (or @annually) | 每年 1 月 1 日的午夜运行一次 | 0 0 1 1 * |
136+
| @yearly ( @annually) | 每年 1 月 1 日的午夜运行一次 | 0 0 1 1 * |
136137
| @monthly | 每月第一天的午夜运行一次 | 0 0 1 * * |
137138
| @weekly | 每周的周日午夜运行一次 | 0 0 * * 0 |
138-
| @daily (or @midnight) | 每天午夜运行一次 | 0 0 * * * |
139+
| @daily ( @midnight) | 每天午夜运行一次 | 0 0 * * * |
139140
| @hourly | 每小时的开始一次 | 0 * * * * |
140141

141142
<!--
@@ -153,39 +154,36 @@ To generate CronJob schedule expressions, you can also use web tools like [cront
153154
<!--
154155
## Time zones
155156
For CronJobs with no time zone specified, the kube-controller-manager interprets schedules relative to its local time zone.
157+
-->
158+
## 时区 {#time-zones}
159+
160+
对于没有指定时区的 CronJob,kube-controller-manager 基于本地时区解释排期表(Schedule)。
156161

157162
{{< feature-state for_k8s_version="v1.25" state="beta" >}}
158163

164+
<!--
159165
If you enable the `CronJobTimeZone` [feature gate](/docs/reference/command-line-tools-reference/feature-gates/),
160166
you can specify a time zone for a CronJob (if you don't enable that feature gate, or if you are using a version of
161167
Kubernetes that does not have experimental time zone support, all CronJobs in your cluster have an unspecified
162168
timezone).
163169
164-
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) name. For example, setting
170+
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
165171
`spec.timeZone: "Etc/UTC"` instructs Kubernetes to interpret the schedule relative to Coordinated Universal Time.
166172
167173
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.
168174
-->
169-
170-
## 时区 {#time-zones}
171-
对于没有指定时区的 CronJob,kube-controller-manager 基于本地时区解释排期表(Schedule)。
172-
173-
{{< feature-state for_k8s_version="v1.25" state="beta" >}}
174-
175175
如果启用了 `CronJobTimeZone` [特性门控](/zh-cn/docs/reference/command-line-tools-reference/feature-gates/)
176176
你可以为 CronJob 指定一个时区(如果你没有启用该特性门控,或者你使用的是不支持试验性时区功能的
177177
Kubernetes 版本,集群中所有 CronJob 的时区都是未指定的)。
178178

179179
启用该特性后,你可以将 `spec.timeZone`
180-
设置为有效[时区](https://zh.wikipedia.org/wiki/%E6%97%B6%E5%8C%BA%E4%BF%A1%E6%81%AF%E6%95%B0%E6%8D%AE%E5%BA%93)名称。
180+
设置为有效[时区](https://zh.wikipedia.org/wiki/%E6%97%B6%E5%8C%BA%E4%BF%A1%E6%81%AF%E6%95%B0%E6%8D%AE%E5%BA%93)名称。
181181
例如,设置 `spec.timeZone: "Etc/UTC"` 指示 Kubernetes 采用 UTC 来解释排期表。
182182

183183
Go 标准库中的时区数据库包含在二进制文件中,并用作备用数据库,以防系统上没有可用的外部数据库。
184184

185-
186185
<!--
187-
188-
## CronJob Limitations
186+
## CronJob limitations {#cron-job-limitations}
189187
190188
A cron job creates a job object _about_ once per execution time of its schedule. We say "about" because there
191189
are certain circumstances where two jobs might be created, or no job might be created. We attempt to make these rare,
@@ -195,7 +193,7 @@ but do not completely prevent them. Therefore, jobs should be _idempotent_.
195193

196194
CronJob 根据其计划编排,在每次该执行任务的时候大约会创建一个 Job。
197195
我们之所以说 "大约",是因为在某些情况下,可能会创建两个 Job,或者不会创建任何 Job。
198-
我们试图使这些情况尽量少发生,但不能完全杜绝。因此,Job 应该是 _幂等的_
196+
我们试图使这些情况尽量少发生,但不能完全杜绝。因此,Job 应该是 **幂等的**
199197

200198
<!--
201199
If `startingDeadlineSeconds` is set to a large value or left unset (the default)
@@ -214,15 +212,15 @@ If `startingDeadlineSeconds` is set to a value less than 10 seconds, the CronJob
214212
{{< /caution >}}
215213

216214
<!--
217-
For every CronJob, the CronJob {{< glossary_tooltip term_id="controller" >}} checks how many schedules it missed in the duration from its last scheduled time until now. If there are more than 100 missed schedules, then it does not start the job and logs the error
215+
For every CronJob, the CronJob {{< glossary_tooltip term_id="controller" >}} checks how many schedules it missed in the duration from its last scheduled time until now. If there are more than 100 missed schedules, then it does not start the job and logs the error.
218216
-->
219217
对于每个 CronJob,CronJob {{< glossary_tooltip term_text="控制器" term_id="controller" >}}
220218
检查从上一次调度的时间点到现在所错过了调度次数。如果错过的调度次数超过 100 次,
221219
那么它就不会启动这个任务,并记录这个错误:
222220

223-
````
221+
```
224222
Cannot determine if job needs to be started. Too many missed start time (> 100). Set or decrease .spec.startingDeadlineSeconds or check clock skew.
225-
````
223+
```
226224

227225
<!--
228226
It is important to note that if the `startingDeadlineSeconds` field is set (not `nil`), the controller counts how many missed jobs occurred from the value of `startingDeadlineSeconds` until now rather than from the last scheduled time until now. For example, if `startingDeadlineSeconds` is `200`, the controller counts how many missed jobs occurred in the last 200 seconds.
@@ -232,7 +230,7 @@ It is important to note that if the `startingDeadlineSeconds` field is set (not
232230
例如,如果 `startingDeadlineSeconds``200`,则控制器会统计在过去 200 秒中错过了多少次 Job。
233231

234232
<!--
235-
A CronJob is counted as missed if it has failed to be created at its scheduled time. For example, If `concurrencyPolicy` is set to `Forbid` and a CronJob was attempted to be scheduled when there was a previous schedule still running, then it would count as missed.
233+
A CronJob is counted as missed if it has failed to be created at its scheduled time. For example, if `concurrencyPolicy` is set to `Forbid` and a CronJob was attempted to be scheduled when there was a previous schedule still running, then it would count as missed.
236234
-->
237235
如果未能在调度时间内创建 CronJob,则计为错过。
238236
例如,如果 `concurrencyPolicy` 被设置为 `Forbid`,并且当前有一个调度仍在运行的情况下,
@@ -245,16 +243,16 @@ be down from `08:29:00` to `10:21:00`, the job will not start as the number of m
245243
-->
246244
例如,假设一个 CronJob 被设置为从 `08:30:00` 开始每隔一分钟创建一个新的 Job,
247245
并且它的 `startingDeadlineSeconds` 字段未被设置。如果 CronJob 控制器从
248-
`08:29:00``10:21:00` 终止运行,则该 Job 将不会启动,因为其错过的调度
249-
次数超过了 100。
246+
`08:29:00``10:21:00` 终止运行,则该 Job 将不会启动,
247+
因为其错过的调度次数超过了 100。
250248

251249
<!--
252250
To illustrate this concept further, suppose a CronJob is set to schedule a new Job every one minute beginning at `08:30:00`, and its
253251
`startingDeadlineSeconds` is set to 200 seconds. If the CronJob controller happens to
254-
be down for the same period as the previous example (`08:29:00` to `10:21:00`,) the Job will still start at 10:22:00. This happens as the controller now checks how many missed schedules happened in the last 200 seconds (ie, 3 missed schedules), rather than from the last scheduled time until now.
252+
be down for the same period as the previous example (`08:29:00` to `10:21:00`,) the Job will still start at 10:22:00. This happens as the controller now checks how many missed schedules happened in the last 200 seconds (i.e., 3 missed schedules), rather than from the last scheduled time until now.
255253
-->
256254
为了进一步阐述这个概念,假设将 CronJob 设置为从 `08:30:00` 开始每隔一分钟创建一个新的 Job,
257-
并将其 `startingDeadlineSeconds` 字段设置为 200 秒。
255+
并将其 `startingDeadlineSeconds` 字段设置为 200 秒。
258256
如果 CronJob 控制器恰好在与上一个示例相同的时间段(`08:29:00``10:21:00`)终止运行,
259257
则 Job 仍将从 `10:22:00` 开始。
260258
造成这种情况的原因是控制器现在检查在最近 200 秒(即 3 个错过的调度)中发生了多少次错过的
@@ -271,7 +269,7 @@ CronJob 仅负责创建与其调度时间相匹配的 Job,而 Job 又负责管
271269
272270
Starting with Kubernetes v1.21 the second version of the CronJob controller
273271
is the default implementation. To disable the default CronJob controller
274-
and use the original CronJob controller instead, one pass the `CronJobControllerV2`
272+
and use the original CronJob controller instead, pass the `CronJobControllerV2`
275273
[feature gate](/docs/reference/command-line-tools-reference/feature-gates/)
276274
flag to the {{< glossary_tooltip term_id="kube-controller-manager" text="kube-controller-manager" >}},
277275
and set this flag to `false`. For example:
@@ -289,6 +287,7 @@ and set this flag to `false`. For example:
289287
```
290288

291289
## {{% heading "whatsnext" %}}
290+
292291
<!--
293292
* Learn about [Pods](/docs/concepts/workloads/pods/) and
294293
[Jobs](/docs/concepts/workloads/controllers/job/), two concepts
@@ -304,11 +303,10 @@ and set this flag to `false`. For example:
304303
Read the {{< api-reference page="workload-resources/cron-job-v1" >}}
305304
object definition to understand the API for Kubernetes cron jobs.
306305
-->
307-
308306
* 了解 CronJob 所依赖的 [Pod](/zh-cn/docs/concepts/workloads/pods/)[Job](/zh-cn/docs/concepts/workloads/controllers/job/) 的概念。
309307
* 阅读 CronJob `.spec.schedule` 字段的[格式](https://pkg.go.dev/github.com/robfig/cron/v3#hdr-CRON_Expression_Format)
310-
* 有关创建和使用 CronJob 的说明及示例规约文件,请参见
311-
[使用 CronJob 运行自动化任务](/zh-cn/docs/tasks/job/automated-tasks-with-cron-jobs/)
308+
* 有关创建和使用 CronJob 的说明及示例规约文件,
309+
请参见[使用 CronJob 运行自动化任务](/zh-cn/docs/tasks/job/automated-tasks-with-cron-jobs/)
312310
* 有关自动清理失败或完成作业的说明,请参阅[自动清理作业](/zh-cn/docs/concepts/workloads/controllers/job/#clean-up-finished-jobs-automatically)
313311
* `CronJob` 是 Kubernetes REST API 的一部分,
314312
阅读 {{< api-reference page="workload-resources/cron-job-v1" >}}

0 commit comments

Comments
 (0)