@@ -50,13 +50,13 @@ Here is an overview of the steps in this example:
50
50
51
51
<!--
52
52
Be familiar with the basic,
53
- non-parallel, use of [Job](/docs/concepts/jobs/run-to-completion-finite- workloads/).
53
+ non-parallel, use of [Job](/docs/concepts/workloads/controllers/job /).
54
54
-->
55
55
56
56
要熟悉 Job 基本用法(非并行的),请参考
57
57
[ Job] ( /zh-cn/docs/concepts/workloads/controllers/job/ ) 。
58
58
59
- {{< include "task-tutorial-prereqs.md" >}} {{< version-check >}}
59
+ {{< include "task-tutorial-prereqs.md" >}}
60
60
61
61
<!-- steps -->
62
62
@@ -70,7 +70,7 @@ cluster and reuse it for many jobs, as well as for long-running services.
70
70
71
71
Start RabbitMQ as follows:
72
72
-->
73
- ## 启动消息队列服务
73
+ ## 启动消息队列服务 {#starting-a-message-queue-service}
74
74
75
75
本例使用了 RabbitMQ,但你可以更改该示例,使用其他 AMQP 类型的消息服务。
76
76
@@ -108,7 +108,7 @@ and experiment with queues.
108
108
109
109
First create a temporary interactive Pod.
110
110
-->
111
- ## 测试消息队列服务
111
+ ## 测试消息队列服务 {#testing-the-message-queue-service}
112
112
113
113
现在,我们可以试着访问消息队列。我们将会创建一个临时的可交互的 Pod,在它上面安装一些工具,然后用队列做实验。
114
114
@@ -154,7 +154,7 @@ Next, we will check that we can discover the rabbitmq service:
154
154
# Note the rabbitmq-service has a DNS name, provided by Kubernetes:
155
155
-->
156
156
```
157
- # 请注意 rabbitmq-service 有Kubernetes 提供的 DNS 名称,
157
+ # 请注意 rabbitmq-service 拥有一个由 Kubernetes 提供的 DNS 名称:
158
158
159
159
root@temp-loe07:/# nslookup rabbitmq-service
160
160
Server: 10.0.0.10
@@ -196,8 +196,6 @@ Next we will verify we can create a queue, and publish and consume messages.
196
196
# then use this command instead:
197
197
# root@temp-loe07:/# BROKER_URL=amqp://guest:guest@$RABBITMQ_SERVICE_SERVICE_HOST:5672
198
198
# Now create a queue:
199
- # and publish a message to it:
200
- # and get it back.
201
199
-->
202
200
203
201
``` shell
@@ -246,7 +244,7 @@ In a practice, the content of the messages might be:
246
244
- configuration parameters to a simulation
247
245
- frame numbers of a scene to be rendered
248
246
-->
249
- ## 为队列增加任务
247
+ ## 为队列增加任务 {#filling-the-queue-with-tasks}
250
248
251
249
现在让我们给队列增加一些任务。在我们的示例中,任务是多个待打印的字符串。
252
250
@@ -268,7 +266,9 @@ For our example, we will create the queue and fill it using the amqp command lin
268
266
In practice, you might write a program to fill the queue using an amqp client library.
269
267
-->
270
268
271
- 本例中,如果有大量的数据需要被 Job 的所有 Pod 读取,典型的做法是把它们放在一个共享文件系统中,如NFS,并以只读的方式挂载到所有 Pod,或者 Pod 中的程序从类似 HDFS 的集群文件系统中读取。
269
+ 本例中,如果有大量的数据需要被 Job 的所有 Pod 读取,典型的做法是把它们放在一个共享文件系统中,
270
+ 如 NFS(Network File System 网络文件系统),并以只读的方式挂载到所有 Pod,或者 Pod 中的程序从类似 HDFS
271
+ (Hadoop Distributed File System 分布式文件系统)的集群文件系统中读取。
272
272
273
273
例如,我们创建队列并使用 amqp 命令行工具向队列中填充消息。实践中,你可以写个程序来利用 amqp 客户端库来填充这些队列。
274
274
@@ -294,14 +294,24 @@ example program:
294
294
-->
295
295
这样,我们给队列中填充了8个消息。
296
296
297
- ## 创建镜像
297
+ ## 创建镜像 {#create-an-image}
298
298
299
299
现在我们可以创建一个做为 Job 来运行的镜像。
300
300
301
301
我们将用 ` amqp-consume ` 来从队列中读取消息并实际运行我们的程序。这里给出一个非常简单的示例程序:
302
302
303
303
{{< codenew language="python" file="application/job/rabbitmq/worker.py" >}}
304
304
305
+ <!--
306
+ Give the script execution permission:
307
+ -->
308
+ 赋予脚本执行权限:
309
+
310
+ ``` shell
311
+ chmod +x worker.py
312
+ ```
313
+
314
+
305
315
<!--
306
316
Now, build an image. If you are working in the source
307
317
tree, then change directory to `examples/job/work-queue-1`.
@@ -355,7 +365,7 @@ gcloud docker -- push gcr.io/<project>/job-wq-1
355
365
Here is a job definition. You'll need to make a copy of the Job and edit the
356
366
image to match the name you used, and call it `./job.yaml`.
357
367
-->
358
- ## 定义 Job
368
+ ## 定义 Job {#defining-a-job}
359
369
360
370
这里给出一个 Job 定义 yaml文件。你需要拷贝一份并编辑镜像以匹配你使用的名称,保存为 ` ./job.yaml ` 。
361
371
@@ -372,18 +382,17 @@ So, now run the Job:
372
382
-->
373
383
本例中,每个 Pod 使用队列中的一个消息然后退出。这样,Job 的完成计数就代表了完成的工作项的数量。本例中我们设置 ` .spec.completions: 8 ` ,因为我们放了8项内容在队列中。
374
384
375
- ## 运行 Job
385
+ ## 运行 Job {#running-the-job}
376
386
377
387
现在我们运行 Job:
378
388
379
389
``` shell
380
- kubectl create -f ./job.yaml
390
+ kubectl apply -f ./job.yaml
381
391
```
382
392
383
393
<!--
384
394
Now wait a bit, then check on the job.
385
395
-->
386
-
387
396
稍等片刻,然后检查 Job。
388
397
389
398
``` shell
@@ -441,9 +450,9 @@ do not need to modify your "worker" program to be aware that there is a work que
441
450
442
451
It does require that you run a message queue service.
443
452
If running a queue service is inconvenient, you may
444
- want to consider one of the other [job patterns](/docs/concepts/jobs/run-to-completion-finite- workloads/#job-patterns).
453
+ want to consider one of the other [job patterns](/docs/concepts/workloads/controllers/job /#job-patterns).
445
454
-->
446
- ## 替代方案
455
+ ## 替代方案 {#alternatives}
447
456
448
457
本文所讲述的处理方法的好处是你不需要修改你的 "worker" 程序使其知道工作队列的存在。
449
458
@@ -455,7 +464,7 @@ This approach creates a pod for every work item. If your work items only take a
455
464
though, creating a Pod for every work item may add a lot of overhead. Consider another
456
465
[example](/docs/tasks/job/fine-parallel-processing-work-queue/), that executes multiple work items per Pod.
457
466
458
- In this example, we used use the `amqp-consume` utility to read the message
467
+ In this example, we use the `amqp-consume` utility to read the message
459
468
from the queue and run our actual program. This has the advantage that you
460
469
do not need to modify your program to be aware of the queue.
461
470
A [different example](/docs/tasks/job/fine-parallel-processing-work-queue/), shows how to
@@ -489,7 +498,7 @@ exits with success, or if the node crashes before the kubelet is able to post th
489
498
back to the api-server, then the Job will not appear to be complete, even though all items
490
499
in the queue have been processed.
491
500
-->
492
- ## 友情提醒
501
+ ## 友情提醒 {#caveats}
493
502
494
503
如果设置的完成数量小于队列中的消息数量,会导致一部分消息项不会被执行。
495
504
0 commit comments