Skip to content

Commit dd34013

Browse files
committed
[zh] Sync workloads
1 parent a7d02c4 commit dd34013

File tree

2 files changed

+136
-106
lines changed

2 files changed

+136
-106
lines changed

content/zh/docs/concepts/workloads/controllers/job.md

Lines changed: 60 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ The Job object will start a new Pod if the first Pod fails or is deleted (for ex
3333
due to a node hardware failure or a node reboot).
3434
3535
You can also use a Job to run multiple Pods in parallel.
36+
37+
If you want to run a Job (either a single task, or several in parallel) on a schedule,
38+
see [CronJob](/docs/concepts/workloads/controllers/cron-jobs/).
3639
-->
3740
Job 会创建一个或者多个 Pods,并将继续重试 Pods 的执行,直到指定数量的 Pods 成功终止。
3841
随着 Pods 成功结束,Job 跟踪记录成功完成的 Pods 个数。
@@ -46,7 +49,11 @@ Job 会创建一个或者多个 Pods,并将继续重试 Pods 的执行,直
4649

4750
你也可以使用 Job 以并行的方式运行多个 Pod。
4851

52+
如果你想按某种排期表(Schedule)运行 Job(单个任务或多个并行任务),请参阅
53+
[CronJob](/docs/concepts/workloads/controllers/cron-jobs/)
54+
4955
<!-- body -->
56+
5057
<!--
5158
## Running an example Job
5259
@@ -60,26 +67,36 @@ It takes around 10s to complete.
6067

6168
{{< codenew file="controllers/job.yaml" >}}
6269

63-
<!--You can run the example with this command:-->
70+
<!--
71+
You can run the example with this command:
72+
-->
6473
你可以使用下面的命令来运行此示例:
6574

6675
```shell
6776
kubectl apply -f https://kubernetes.io/examples/controllers/job.yaml
6877
```
69-
<!--The output is similar to this:-->
78+
79+
<!--
80+
The output is similar to this:
81+
-->
7082
输出类似于:
7183

7284
```
7385
job.batch/pi created
7486
```
7587

76-
<!-- Check on the status of the Job with `kubectl`: -->
88+
<!--
89+
Check on the status of the Job with `kubectl`:
90+
-->
7791
使用 `kubectl` 来检查 Job 的状态:
7892

7993
```shell
8094
kubectl describe jobs/pi
8195
```
82-
<!--The output is similar to this:-->
96+
97+
<!--
98+
The output is similar to this:
99+
-->
83100
输出类似于:
84101

85102
```
@@ -131,15 +148,18 @@ To list all the Pods that belong to a Job in a machine readable form, you can us
131148
pods=$(kubectl get pods --selector=job-name=pi --output=jsonpath='{.items[*].metadata.name}')
132149
echo $pods
133150
```
134-
<!--The output is similar to this:-->
151+
152+
<!--
153+
The output is similar to this:
154+
-->
135155
输出类似于:
136156

137157
```
138158
pi-5rwd7
139159
```
140160

141161
<!--
142-
Here, the selector is the same as the selector for the Job. The `-output=jsonpath` option specifies an expression
162+
Here, the selector is the same as the selector for the Job. The `--output=jsonpath` option specifies an expression
143163
with the name from each Pod in the returned list.
144164
145165
View the standard output of one of the pods:
@@ -153,12 +173,15 @@ View the standard output of one of the pods:
153173
kubectl logs $pods
154174
```
155175

156-
<!--The output is similar to this:-->
176+
<!--
177+
The output is similar to this:
178+
-->
157179
输出类似于:
158180

159181
```
160182
3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989380952572010654858632788659361533818279682303019520353018529689957736225994138912497217752834791315155748572424541506959508295331168617278558890750983817546374649393192550604009277016711390098488240128583616035637076601047101819429555961989467678374494482553797747268471040475346462080466842590694912933136770289891521047521620569660240580381501935112533824300355876402474964732639141992726042699227967823547816360093417216412199245863150302861829745557067498385054945885869269956909272107975093029553211653449872027559602364806654991198818347977535663698074265425278625518184175746728909777727938000816470600161452491921732172147723501414419735685481613611573525521334757418494684385233239073941433345477624168625189835694855620992192221842725502542568876717904946016534668049886272327917860857843838279679766814541009538837863609506800642251252051173929848960841284886269456042419652850222106611863067442786220391949450471237137869609563643719172874677646575739624138908658326459958133904780275901
161183
```
184+
162185
<!--
163186
## Writing a Job spec
164187
@@ -167,12 +190,12 @@ Its name must be a valid [DNS subdomain name](/docs/concepts/overview/working-wi
167190
168191
A Job also needs a [`.spec` section](https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status).
169192
-->
170-
## 编写 Job 规约
193+
## 编写 Job 规约 {#writing-a-job-spec}
171194

172195
与 Kubernetes 中其他资源的配置类似,Job 也需要 `apiVersion``kind``metadata` 字段。
173196
Job 的名字必须是合法的 [DNS 子域名](/zh/docs/concepts/overview/working-with-objects/names#dns-subdomain-names)
174197

175-
Job 配置还需要一个[`.spec`](https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status)
198+
Job 配置还需要一个 [`.spec`](https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status)
176199

177200
<!--
178201
### Pod Template
@@ -186,7 +209,7 @@ labels (see [pod selector](#pod-selector)) and an appropriate restart policy.
186209
187210
Only a [`RestartPolicy`](/docs/concepts/workloads/pods/pod-lifecycle/#restart-policy) equal to `Never` or `OnFailure` is allowed.
188211
-->
189-
### Pod 模版
212+
### Pod 模版 {#pod-template}
190213

191214
Job 的 `.spec` 中只有 `.spec.template` 是必需的字段。
192215

@@ -195,7 +218,7 @@ Job 的 `.spec` 中只有 `.spec.template` 是必需的字段。
195218
完全相同,只是其中不再需要 `apiVersion``kind` 字段。
196219

197220
除了作为 Pod 所必需的字段之外,Job 中的 Pod 模版必需设置合适的标签
198-
(参见[Pod 选择算符](#pod-selector))和合适的重启策略。
221+
(参见 [Pod 选择算符](#pod-selector))和合适的重启策略。
199222

200223
Job 中 Pod 的 [`RestartPolicy`](/zh/docs/concepts/workloads/pods/pod-lifecycle/#restart-policy)
201224
只能设置为 `Never``OnFailure` 之一。
@@ -219,6 +242,7 @@ There are three main types of task suitable to run as a Job:
219242
### Job 的并行执行 {#parallel-jobs}
220243

221244
适合以 Job 形式来运行的任务主要有三种:
245+
222246
<!--
223247
1. Non-parallel Jobs
224248
- normally, only one Pod is started, unless the Pod fails.
@@ -298,7 +322,7 @@ parallelism, for a variety of reasons:
298322
<!--
299323
- For _fixed completion count_ Jobs, the actual number of pods running in parallel will not exceed the number of
300324
remaining completions. Higher values of `.spec.parallelism` are effectively ignored.
301-
- For _work queue_ Jobs, no new Pods are started after any Pod has succeeded - remaining Pods are allowed to complete, however.
325+
- For _work queue_ Jobs, no new Pods are started after any Pod has succeeded -- remaining Pods are allowed to complete, however.
302326
- If the Job {{< glossary_tooltip term_id="controller" >}} has not had time to react.
303327
- If the Job controller failed to create Pods for any reason (lack of `ResourceQuota`, lack of permission, etc.),
304328
then there may be fewer pods than requested.
@@ -377,7 +401,7 @@ restarted locally, or else specify `.spec.template.spec.restartPolicy = "Never"`
377401
See [pod lifecycle](/docs/concepts/workloads/pods/pod-lifecycle/#example-states) for more information on `restartPolicy`.
378402
-->
379403

380-
## 处理 Pod 和容器失效
404+
## 处理 Pod 和容器失效 {#handling-pod-and-container-failures}
381405

382406
Pod 中的容器可能因为多种不同原因失效,例如因为其中的进程退出时返回值非零,
383407
或者容器因为超出内存约束而被杀死等等。
@@ -430,7 +454,7 @@ exponential back-off delay (10s, 20s, 40s ...) capped at six minutes. The
430454
back-off count is reset when a Job's Pod is deleted or successful without any
431455
other Pods for the Job failing around that time.
432456
-->
433-
### Pod 回退失效策略
457+
### Pod 回退失效策略 {#pod-backoff-failure-policy}
434458

435459
在有些情形下,你可能希望 Job 在经历若干次重试之后直接进入失败状态,因为这很
436460
可能意味着遇到了配置错误。
@@ -463,7 +487,7 @@ allows you to still view the logs of completed pods to check for errors, warning
463487
The job object also remains after it is completed so that you can view its status. It is up to the user to delete
464488
old jobs after noting their status. Delete the job with `kubectl` (e.g. `kubectl delete jobs/pi` or `kubectl delete -f ./job.yaml`). When you delete the job using `kubectl`, all the pods it created are deleted too.
465489
-->
466-
## Job 终止与清理
490+
## Job 终止与清理 {#clean-up-finished-jobs-automatically}
467491

468492
Job 完成时不会再创建新的 Pod,不过已有的 Pod [通常](#pod-backoff-failure-policy)也不会被删除。
469493
保留这些 Pod 使得你可以查看已完成的 Pod 的日志输出,以便检查错误、警告
@@ -732,7 +756,7 @@ Job 被创建时,Job 控制器会马上开始执行 Pod 创建操作以满足
732756
不过你可能想要暂时挂起 Job 执行,或启动处于挂起状态的job,
733757
并拥有一个自定义控制器以后再决定什么时候开始。
734758

735-
<!--
759+
<!--
736760
To suspend a Job, you can update the `.spec.suspend` field of
737761
the Job to true; later, when you want to resume it again, update it to false.
738762
Creating a Job with `.spec.suspend` set to true will create it in the suspended
@@ -911,7 +935,7 @@ Job 的 Pod 模板中可以更新的字段是节点亲和性、节点选择器
911935
912936
913937
<!--
914-
### Specifying your own Pod selector {#specifying-your-own-pod-selector}
938+
### Specifying your own Pod selector
915939
916940
Normally, when you create a Job object, you do not specify `.spec.selector`.
917941
The system defaulting logic adds this field when the Job is created.
@@ -971,7 +995,10 @@ Before deleting it, you make a note of what selector it uses:
971995
```shell
972996
kubectl get job old -o yaml
973997
```
974-
<!--The output is similar to this:-->
998+
999+
<!--
1000+
The output is similar to this:
1001+
-->
9751002
输出类似于:
9761003

9771004
```yaml
@@ -999,7 +1026,7 @@ the selector that the system normally generates for you automatically.
9991026
它们也会被名为 `new` 的 Job 所控制。
10001027

10011028
你需要在新 Job 中设置 `manualSelector: true`,因为你并未使用系统通常自动为你
1002-
生成的选择算符。
1029+
生成的选择算符。
10031030

10041031
```yaml
10051032
kind: Job
@@ -1025,29 +1052,31 @@ mismatch.
10251052

10261053
<!--
10271054
### Job tracking with finalizers
1055+
-->
1056+
### 使用 Finalizer 追踪 Job {#job-tracking-with-finalizers}
10281057

1058+
{{< feature-state for_k8s_version="v1.23" state="beta" >}}
1059+
1060+
{{< note >}}
1061+
<!--
10291062
In order to use this behavior, you must enable the `JobTrackingWithFinalizers`
10301063
[feature gate](/docs/reference/command-line-tools-reference/feature-gates/)
10311064
on the [API server](/docs/reference/command-line-tools-reference/kube-apiserver/)
10321065
and the [controller manager](/docs/reference/command-line-tools-reference/kube-controller-manager/).
10331066
It is enabled by default.
1034-
1035-
When enabled, the control plane tracks new Jobs using the behavior described
1036-
below. Jobs created before the feature was enabled are unaffected. As a user,
1037-
the only difference you would see is that the control plane tracking of Job
1038-
completion is more accurate.
10391067
-->
1040-
### 使用 Finalizer 追踪 Job {#job-tracking-with-finalizers}
1041-
1042-
{{< feature-state for_k8s_version="v1.23" state="beta" >}}
1043-
1044-
{{< note >}}
10451068
要使用该行为,你必须为 [API 服务器](/zh/docs/reference/command-line-tools-reference/kube-apiserver/)
10461069
[控制器管理器](/zh/docs/reference/command-line-tools-reference/kube-controller-manager/)
10471070
启用 `JobTrackingWithFinalizers`
10481071
[特性门控](/zh/docs/reference/command-line-tools-reference/feature-gates/)
10491072
默认是启用的。
10501073

1074+
<!--
1075+
When enabled, the control plane tracks new Jobs using the behavior described
1076+
below. Jobs created before the feature was enabled are unaffected. As a user,
1077+
the only difference you would see is that the control plane tracking of Job
1078+
completion is more accurate.
1079+
-->
10511080
启用后,控制面基于下述行为追踪新的 Job。在启用该特性之前创建的 Job 不受影响。
10521081
作为用户,你会看到的唯一区别是控制面对 Job 完成情况的跟踪更加准确。
10531082
{{< /note >}}
@@ -1117,7 +1146,7 @@ Job 会重新创建新的 Pod 来替代已终止的 Pod。
11171146
<!--
11181147
### Replication Controller
11191148
1120-
Jobs are complementary to [Replication Controllers](/docs/user-guide/replication-controller).
1149+
Jobs are complementary to [Replication Controllers](/docs/concepts/workloads/controllers/replicationcontroller/).
11211150
A Replication Controller manages Pods which are not expected to terminate (e.g. web servers), and a Job
11221151
manages Pods that are expected to terminate (e.g. batch tasks).
11231152
@@ -1142,7 +1171,7 @@ Another pattern is for a single Job to create a Pod which then creates other Pod
11421171
of custom controller for those Pods. This allows the most flexibility, but may be somewhat
11431172
complicated to get started with and offers less integration with Kubernetes.
11441173
-->
1145-
### 单个 Job 启动控制器 Pod
1174+
### 单个 Job 启动控制器 Pod {#single-job-starts-controller-pod}
11461175

11471176
另一种模式是用唯一的 Job 来创建 Pod,而该 Pod 负责启动其他 Pod,因此扮演了一种
11481177
后启动 Pod 的控制器的角色。

0 commit comments

Comments
 (0)