Skip to content

Commit dabb6d6

Browse files
committed
[zh] Tidy up and fix links in tasks section (9/10)
1 parent fb6364d commit dabb6d6

9 files changed

+781
-717
lines changed

content/zh/docs/tasks/access-application-cluster/communicate-containers-same-pod-shared-volume.md

Lines changed: 142 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -2,168 +2,212 @@
22
title: 同 Pod 内的容器使用共享卷通信
33
content_type: task
44
---
5-
6-
5+
<!--
6+
title: Communicate Between Containers in the Same Pod Using a Shared Volume
7+
content_type: task
8+
weight: 110
9+
-->
710
<!-- overview -->
811

12+
<!--
13+
This page shows how to use a Volume to communicate between two Containers running
14+
in the same Pod. See also how to allow processes to communicate by
15+
[sharing process namespace](/docs/tasks/configure-pod-container/share-process-namespace/)
16+
between containers.
17+
-->
918
本文旨在说明如何让一个 Pod 内的两个容器使用一个卷(Volume)进行通信。
10-
11-
19+
参阅如何让两个进程跨容器通过
20+
[共享进程名字空间](/zh/docs/tasks/configure-pod-container/share-process-namespace/)
1221

1322
## {{% heading "prerequisites" %}}
1423

15-
1624
{{< include "task-tutorial-prereqs.md" >}} {{< version-check >}}
1725

18-
19-
20-
2126
<!-- steps -->
2227

28+
<!--
29+
## Creating a Pod that runs two Containers
2330
31+
In this exercise, you create a Pod that runs two Containers. The two containers
32+
share a Volume that they can use to communicate. Here is the configuration file
33+
for the Pod:
34+
-->
2435
## 创建一个包含两个容器的 Pod
2536

2637
在这个练习中,你会创建一个包含两个容器的 Pod。两个容器共享一个卷用于他们之间的通信。
2738
Pod 的配置文件如下:
2839

2940
{{< codenew file="pods/two-container-pod.yaml" >}}
3041

42+
<!--
43+
In the configuration file, you can see that the Pod has a Volume named
44+
`shared-data`.
45+
46+
The first container listed in the configuration file runs an nginx server. The
47+
mount path for the shared Volume is `/usr/share/nginx/html`.
48+
The second container is based on the debian image, and has a mount path of
49+
`/pod-data`. The second container runs the following command and then terminates.
50+
-->
3151
在配置文件中,你可以看到 Pod 有一个共享卷,名为 `shared-data`
3252

3353
配置文件中的第一个容器运行了一个 nginx 服务器。共享卷的挂载路径是 `/usr/share/nginx/html`
3454
第二个容器是基于 debian 镜像的,有一个 `/pod-data` 的挂载路径。第二个容器运行了下面的命令然后终止。
3555

36-
echo Hello from the debian container > /pod-data/index.html
56+
```shell
57+
echo Hello from the debian container > /pod-data/index.html
58+
```
3759

38-
注意,第二个容器在 nginx 服务器的根目录下写了 `index.html` 文件。
60+
<!--
61+
Notice that the second container writes the `index.html` file in the root
62+
directory of the nginx server.
3963
64+
Create the Pod and the two Containers:
65+
-->
66+
注意,第二个容器在 nginx 服务器的根目录下写了 `index.html` 文件。
4067

4168
创建一个包含两个容器的 Pod:
4269

43-
kubectl apply -f https://k8s.io/examples/pods/two-container-pod.yaml
70+
```shell
71+
kubectl apply -f https://k8s.io/examples/pods/two-container-pod.yaml
72+
```
4473

74+
<!--
75+
View information about the Pod and the Containers:
76+
-->
4577
查看 Pod 和容器的信息:
4678

47-
kubectl get pod two-containers --output=yaml
48-
79+
```shell
80+
kubectl get pod two-containers --output=yaml
81+
```
4982

83+
<!--
84+
Here is a portion of the output:
85+
-->
5086
这是输出的一部分:
5187

52-
apiVersion: v1
53-
kind: Pod
54-
metadata:
55-
...
56-
name: two-containers
57-
namespace: default
58-
...
59-
spec:
60-
...
61-
containerStatuses:
62-
63-
- containerID: docker://c1d8abd1 ...
64-
image: debian
65-
...
66-
lastState:
67-
terminated:
68-
...
69-
name: debian-container
70-
...
71-
72-
- containerID: docker://96c1ff2c5bb ...
73-
image: nginx
88+
```yaml
89+
apiVersion: v1
90+
kind: Pod
91+
metadata:
92+
...
93+
name: two-containers
94+
namespace: default
95+
...
96+
spec:
97+
...
98+
containerStatuses:
99+
100+
- containerID: docker://c1d8abd1 ...
101+
image: debian
102+
...
103+
lastState:
104+
terminated:
74105
...
75-
name: nginx-container
76-
...
77-
state:
78-
running:
79-
...
80-
81-
82-
106+
name: debian-container
107+
...
108+
109+
- containerID: docker://96c1ff2c5bb ...
110+
image: nginx
111+
...
112+
name: nginx-container
113+
...
114+
state:
115+
running:
116+
...
117+
```
118+
119+
<!--
120+
You can see that the debian Container has terminated, and the nginx Container
121+
is still running.
122+
123+
Get a shell to nginx Container:
124+
-->
83125
你可以看到 debian 容器已经被终止了,而 nginx 服务器依然在运行。
84126

85-
86127
进入 nginx 容器的 shell:
87128

88-
kubectl exec -it two-containers -c nginx-container -- /bin/bash
89-
129+
```shell
130+
kubectl exec -it two-containers -c nginx-container -- /bin/bash
131+
```
90132

133+
<!--
134+
In your shell, verify that nginx is running:
135+
-->
91136
在 shell 中,确认 nginx 还在运行。
92137

93-
root@two-containers:/# ps aux
94-
138+
```
139+
root@two-containers:/# ps aux
140+
```
95141

142+
<!--
143+
The output is similar to this:
144+
-->
96145
输出类似于这样:
97146

98-
USER PID ... STAT START TIME COMMAND
99-
root 1 ... Ss 21:12 0:00 nginx: master process nginx -g daemon off;
100-
101-
147+
```
148+
USER PID ... STAT START TIME COMMAND
149+
root 1 ... Ss 21:12 0:00 nginx: master process nginx -g daemon off;
150+
```
102151

152+
<!--
153+
Recall that the debian Container created the `index.html` file in the nginx root
154+
directory. Use `curl` to send a GET request to the nginx server:
155+
-->
103156
回忆一下,debian 容器在 nginx 的根目录下创建了 `index.html` 文件。
104157
使用 `curl` 向 nginx 服务器发送一个 GET 请求:
105158

106-
root@two-containers:/# apt-get update
107-
root@two-containers:/# apt-get install curl
108-
root@two-containers:/# curl localhost
109-
159+
```
160+
root@two-containers:/# apt-get update
161+
root@two-containers:/# apt-get install curl
162+
root@two-containers:/# curl localhost
163+
```
110164

111165
输出表示 nginx 提供了 debian 容器写的页面:
112166

113-
Hello from the debian container
114-
115-
116-
117-
167+
```
168+
Hello from the debian container
169+
```
118170
<!-- discussion -->
119171

120-
172+
<!--
173+
## Discussion
174+
175+
The primary reason that Pods can have multiple containers is to support
176+
helper applications that assist a primary application. Typical examples of
177+
helper applications are data pullers, data pushers, and proxies.
178+
Helper and primary applications often need to communicate with each other.
179+
Typically this is done through a shared filesystem, as shown in this exercise,
180+
or through the loopback network interface, localhost. An example of this pattern is a
181+
web server along with a helper program that polls a Git repository for new updates.
182+
-->
121183
## 讨论
122184

123-
124-
125-
126-
127-
128-
129-
130185
Pod 能有多个容器的主要原因是为了支持辅助应用(helper applications),以协助主应用(primary application)。
131186
辅助应用的典型例子是数据抽取,数据推送和代理。辅助应用和主应用经常需要相互通信。
132187
就如这个练习所示,通信通常是通过共享文件系统完成的,或者,也通过回环网络接口 localhost 完成。
133188
举个网络接口的例子,web 服务器带有一个协助程序用于拉取 Git 仓库的更新。
134189

135-
136-
137-
190+
<!--
191+
The Volume in this exercise provides a way for Containers to communicate during
192+
the life of the Pod. If the Pod is deleted and recreated, any data stored in
193+
the shared Volume is lost.
194+
-->
138195
在本练习中的卷为 Pod 生命周期中的容器相互通信提供了一种方法。如果 Pod 被删除或者重建了,
139196
任何共享卷中的数据都会丢失。
140197

141-
142-
143-
144198
## {{% heading "whatsnext" %}}
145199

146-
147-
148-
149-
* 更多学习内容
150-
[混合容器的方式](http://kubernetes.io/blog/2015/06/the-distributed-system-toolkit-patterns.html)
151-
152-
153-
154-
* 学习 [模块化架构的混合容器](http://www.slideshare.net/Docker/slideshare-burns)
155-
156-
157-
158-
* 参见 [配置一个使用存储卷的 Pod](/docs/tasks/configure-pod-container/configure-volume-storage/)
159-
160-
161-
* 参见 [](/docs/api-reference/{{< param "version" >}}/#volume-v1-core)。
162-
163-
164-
* 参见 [Pod](/docs/api-reference/{{< param "version" >}}/#pod-v1-core).
165-
166-
167-
168-
200+
<!--
201+
* Learn more about [patterns for composite containers](https://kubernetes.io/blog/2015/06/the-distributed-system-toolkit-patterns).
202+
* Learn about [composite containers for modular architecture](https://www.slideshare.net/Docker/slideshare-burns).
203+
* See [Configuring a Pod to Use a Volume for Storage](/docs/tasks/configure-pod-container/configure-volume-storage/).
204+
* See [Configure a Pod to share process namespace between containers in a Pod](/docs/tasks/configure-pod-container/share-process-namespace/)
205+
* See [Volume](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#volume-v1-core).
206+
* See [Pod](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#pod-v1-core).
207+
-->
208+
* 进一步了解[复合容器的模式](https://kubernetes.io/blog/2015/06/the-distributed-system-toolkit-patterns.html)
209+
* 学习[模块化架构中的复合容器](https://www.slideshare.net/Docker/slideshare-burns)
210+
* 参见[配置 Pod 使用卷来存储数据](/zh/docs/tasks/configure-pod-container/configure-volume-storage/)
211+
* 参考 [Volume](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#volume-v1-core)
212+
* 参考 [Pod](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#pod-v1-core)
169213

0 commit comments

Comments
 (0)