Skip to content

Commit 0c63ced

Browse files
authored
Merge pull request #37985 from windsonsea/cppwq
[zh] sync coarse-parallel-processing-work-queue.md
2 parents 90b8a57 + f4d52bf commit 0c63ced

File tree

1 file changed

+49
-36
lines changed

1 file changed

+49
-36
lines changed

content/zh-cn/docs/tasks/job/coarse-parallel-processing-work-queue.md

Lines changed: 49 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,10 @@ weight: 20
66
---
77

88
<!--
9-
---
109
title: Coarse Parallel Processing Using a Work Queue
1110
min-kubernetes-server-version: v1.8
1211
content_type: task
1312
weight: 20
14-
---
1513
-->
1614

1715
<!-- overview -->
@@ -26,24 +24,29 @@ from a task queue, completes it, deletes it from the queue, and exits.
2624
Here is an overview of the steps in this example:
2725
2826
1. **Start a message queue service.** In this example, we use RabbitMQ, but you could use another
29-
one. In practice you would set up a message queue service once and reuse it for many jobs.
27+
one. In practice you would set up a message queue service once and reuse it for many jobs.
3028
1. **Create a queue, and fill it with messages.** Each message represents one task to be done. In
3129
this example, a message is an integer that we will do a lengthy computation on.
3230
1. **Start a Job that works on tasks from the queue**. The Job starts several pods. Each pod takes
33-
one task from the message queue, processes it, and repeats until the end of the queue is reached.
31+
one task from the message queue, processes it, and repeats until the end of the queue is reached.
3432
-->
3533
本例中,我们会运行包含多个并行工作进程的 Kubernetes Job。
3634

3735
本例中,每个 Pod 一旦被创建,会立即从任务队列中取走一个工作单元并完成它,然后将工作单元从队列中删除后再退出。
3836

3937
下面是本次示例的主要步骤:
4038

41-
1. **启动一个消息队列服务** 本例中,我们使用 RabbitMQ,你也可以用其他的消息队列服务。在实际工作环境中,你可以创建一次消息队列服务然后在多个任务中重复使用。
39+
1. **启动一个消息队列服务**
40+
本例中,我们使用 RabbitMQ,你也可以用其他的消息队列服务。
41+
在实际工作环境中,你可以创建一次消息队列服务然后在多个任务中重复使用。
4242

43-
1. **创建一个队列,放上消息数据** 每个消息表示一个要执行的任务。本例中,每个消息是一个整数值。我们将基于这个整数值执行很长的计算操作
44-
45-
1. **启动一个在队列中执行这些任务的 Job**。该 Job 启动多个 Pod。每个 Pod 从消息队列中取走一个任务,处理它,然后重复执行,直到队列的队尾
43+
1. **创建一个队列,放上消息数据**
44+
每个消息表示一个要执行的任务。本例中,每个消息是一个整数值。
45+
我们将基于这个整数值执行很长的计算操作
4646

47+
1. **启动一个在队列中执行这些任务的 Job**
48+
该 Job 启动多个 Pod。每个 Pod 从消息队列中取走一个任务,处理它,
49+
然后重复执行,直到队列的队尾。
4750

4851
## {{% heading "prerequisites" %}}
4952

@@ -96,8 +99,8 @@ replicationcontroller "rabbitmq-controller" created
9699
<!--
97100
We will only use the rabbitmq part from the [celery-rabbitmq example](https://github.com/kubernetes/kubernetes/tree/release-1.3/examples/celery-rabbitmq).
98101
-->
99-
100-
我们仅用到 [celery-rabbitmq 示例](https://github.com/kubernetes/kubernetes/tree/release-1.3/examples/celery-rabbitmq) 中描述的部分功能。
102+
我们仅用到
103+
[celery-rabbitmq 示例](https://github.com/kubernetes/kubernetes/tree/release-1.3/examples/celery-rabbitmq)中描述的部分功能。
101104

102105
<!--
103106
## Testing the message queue service
@@ -110,13 +113,14 @@ First create a temporary interactive Pod.
110113
-->
111114
## 测试消息队列服务 {#testing-the-message-queue-service}
112115

113-
现在,我们可以试着访问消息队列。我们将会创建一个临时的可交互的 Pod,在它上面安装一些工具,然后用队列做实验。
116+
现在,我们可以试着访问消息队列。我们将会创建一个临时的可交互的 Pod,
117+
在它上面安装一些工具,然后用队列做实验。
114118

115119
首先创建一个临时的可交互的 Pod:
116120

117121
```shell
118122
# 创建一个临时的可交互的 Pod
119-
kubectl run -i --tty temp --image ubuntu:14.04
123+
kubectl run -i --tty temp --image ubuntu:18.04
120124
```
121125
```
122126
Waiting for pod default/temp-loe07 to be running, status is Pending, pod ready: false
@@ -130,7 +134,7 @@ Next install the `amqp-tools` so we can work with message queues.
130134
-->
131135
请注意你的 Pod 名称和命令提示符将会不同。
132136

133-
接下来安装 `amqp-tools` ,这样我们就能用消息队列了。
137+
接下来安装 `amqp-tools`,这样我们就能用消息队列了。
134138

135139
```shell
136140
# 安装一些工具
@@ -145,10 +149,9 @@ Later, we will make a docker image that includes these packages.
145149
146150
Next, we will check that we can discover the rabbitmq service:
147151
-->
148-
149152
后续,我们将制作一个包含这些包的 Docker 镜像。
150153

151-
接着,我们将要验证我们发现 RabbitMQ 服务:
154+
接着,我们将要验证可以发现 RabbitMQ 服务:
152155

153156
<!--
154157
# Note the rabbitmq-service has a DNS name, provided by Kubernetes:
@@ -167,7 +170,7 @@ Address: 10.0.147.152
167170
```
168171

169172
<!--
170-
If Kube-DNS is not setup correctly, the previous step may not work for you.
173+
If Kube-DNS is not set up correctly, the previous step may not work for you.
171174
You can also find the service IP in an env var:
172175
-->
173176
如果 Kube-DNS 没有正确安装,上一步可能会出错。
@@ -227,7 +230,7 @@ from the queue, and passes that message to the standard input of an arbitrary co
227230
return so the example is readable.
228231
-->
229232

230-
最后一个命令中, `amqp-consume` 工具从队列中取走了一个消息,并把该消息传递给了随机命令的标准输出。
233+
最后一个命令中,`amqp-consume` 工具从队列中取走了一个消息,并把该消息传递给了随机命令的标准输出。
231234
在这种情况下,`cat` 会打印它从标准输入中读取的字符,echo 会添加回车符以便示例可读。
232235

233236
<!--
@@ -274,8 +277,7 @@ In practice, you might write a program to fill the queue using an amqp client li
274277

275278
```shell
276279
/usr/bin/amqp-declare-queue --url=$BROKER_URL -q job1 -d job1
277-
278-
for f in apple banana cherry date fig grape lemon melon
280+
for f in apple banana cherry date fig grape lemon melon
279281
do
280282
/usr/bin/amqp-publish --url=$BROKER_URL -r job1 -p -b $f
281283
done
@@ -292,13 +294,14 @@ We will use the `amqp-consume` utility to read the message
292294
from the queue and run our actual program. Here is a very simple
293295
example program:
294296
-->
295-
这样,我们给队列中填充了8个消息
297+
这样,我们给队列中填充了 8 个消息
296298

297299
## 创建镜像 {#create-an-image}
298300

299301
现在我们可以创建一个做为 Job 来运行的镜像。
300302

301-
我们将用 `amqp-consume` 来从队列中读取消息并实际运行我们的程序。这里给出一个非常简单的示例程序:
303+
我们将用 `amqp-consume` 实用程序从队列中读取消息并运行实际的程序。
304+
这里给出一个非常简单的示例程序:
302305

303306
{{< codenew language="python" file="application/job/rabbitmq/worker.py" >}}
304307

@@ -323,9 +326,9 @@ build the image with this command:
323326

324327
现在,编译镜像。如果你在用源代码树,那么切换到目录 `examples/job/work-queue-1`
325328
否则的话,创建一个临时目录,切换到这个目录。下载
326-
[Dockerfile](/examples/application/job/rabbitmq/Dockerfile)
329+
[Dockerfile](/examples/application/job/rabbitmq/Dockerfile)
327330
[worker.py](/examples/application/job/rabbitmq/worker.py)
328-
无论哪种情况,都可以用下面的命令编译镜像
331+
无论哪种情况,都可以用下面的命令编译镜像
329332

330333
```shell
331334
docker build -t job-wq-1 .
@@ -367,7 +370,7 @@ image to match the name you used, and call it `./job.yaml`.
367370
-->
368371
## 定义 Job {#defining-a-job}
369372

370-
这里给出一个 Job 定义 yaml文件。你需要拷贝一份并编辑镜像以匹配你使用的名称,保存为 `./job.yaml`
373+
这里给出一个 Job 定义 YAML 文件。你将需要拷贝一份 Job 并编辑该镜像以匹配你使用的名称,保存为 `./job.yaml`
371374

372375
{{< codenew file="application/job/rabbitmq/job.yaml" >}}
373376

@@ -380,7 +383,9 @@ done. So we set, `.spec.completions: 8` for the example, since we put 8 items i
380383
381384
So, now run the Job:
382385
-->
383-
本例中,每个 Pod 使用队列中的一个消息然后退出。这样,Job 的完成计数就代表了完成的工作项的数量。本例中我们设置 `.spec.completions: 8`,因为我们放了8项内容在队列中。
386+
本例中,每个 Pod 使用队列中的一个消息然后退出。
387+
这样,Job 的完成计数就代表了完成的工作项的数量。
388+
本例中我们设置 `.spec.completions: 8`,因为我们放了 8 项内容在队列中。
384389

385390
## 运行 Job {#running-the-job}
386391

@@ -391,14 +396,23 @@ kubectl apply -f ./job.yaml
391396
```
392397

393398
<!--
394-
Now wait a bit, then check on the job.
399+
You can wait for the Job to succeed, with a timeout:
395400
-->
396-
稍等片刻,然后检查 Job
401+
你可以等待 Job 在某个超时时间后成功:
397402

398403
```shell
399-
kubectl describe jobs/job-wq-1
404+
# 状况名称的检查不区分大小写
405+
kubectl wait --for=condition=complete --timeout=300s job/job-wq-1
400406
```
401407

408+
<!--
409+
Next, check on the Job:
410+
-->
411+
接下来查看 Job:
412+
413+
```shell
414+
kubectl describe jobs/job-wq-1
415+
```
402416
```
403417
Name: job-wq-1
404418
Namespace: default
@@ -436,9 +450,9 @@ Events:
436450
```
437451

438452
<!--
439-
All our pods succeeded. Yay.
453+
All the pods for that Job succeeded. Yay.
440454
-->
441-
我们所有的 Pod 都成功了。耶!
455+
该 Job 的所有 Pod 都已成功。耶!
442456

443457
<!-- discussion -->
444458

@@ -456,8 +470,8 @@ want to consider one of the other [job patterns](/docs/concepts/workloads/contro
456470

457471
本文所讲述的处理方法的好处是你不需要修改你的 "worker" 程序使其知道工作队列的存在。
458472

459-
本文所描述的方法需要你运行一个消息队列服务。如果不方便运行消息队列服务,你也许会考虑另外一种
460-
[任务模式](/zh-cn/docs/concepts/workloads/controllers/job/#job-patterns)
473+
本文所描述的方法需要你运行一个消息队列服务。如果不方便运行消息队列服务,
474+
你也许会考虑另外一种[任务模式](/zh-cn/docs/concepts/workloads/controllers/job/#job-patterns)
461475

462476
<!--
463477
This approach creates a pod for every work item. If your work items only take a few seconds,
@@ -470,16 +484,15 @@ do not need to modify your program to be aware of the queue.
470484
A [different example](/docs/tasks/job/fine-parallel-processing-work-queue/), shows how to
471485
communicate with the work queue using a client library.
472486
-->
473-
474487
本文所述的方法为每个工作项创建了一个 Pod。
475-
如果你的工作项仅需数秒钟,为每个工作项创建 Pod会增加很多的常规消耗
488+
如果你的工作项仅需数秒钟,为每个工作项创建 Pod 会增加很多的常规消耗
476489
可以考虑另外的方案请参考[示例](/zh-cn/docs/tasks/job/fine-parallel-processing-work-queue/)
477490
这种方案可以实现每个 Pod 执行多个工作项。
478491

479492
示例中,我们使用 `amqp-consume` 从消息队列读取消息并执行我们真正的程序。
480493
这样的好处是你不需要修改你的程序使其知道队列的存在。
481-
要了解怎样使用客户端库和工作队列通信,请参考
482-
[不同的示例](/zh-cn/docs/tasks/job/fine-parallel-processing-work-queue/)
494+
要了解怎样使用客户端库和工作队列通信,
495+
请参考[不同的示例](/zh-cn/docs/tasks/job/fine-parallel-processing-work-queue/)
483496

484497
<!--
485498
## Caveats

0 commit comments

Comments
 (0)