Skip to content

Commit d747af0

Browse files
authored
Merge pull request #34688 from fenggw-fnst/tweak-shared-proc-ns
[zh-cn] Update share-process-namespace.md
2 parents ebde34e + 84289e9 commit d747af0

File tree

1 file changed

+106
-82
lines changed

1 file changed

+106
-82
lines changed
Lines changed: 106 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
---
22
title: 在 Pod 中的容器之间共享进程命名空间
3-
min-kubernetes-server-version: v1.10
43
content_type: task
54
weight: 160
65
---
76
<!--
87
---
98
title: Share Process Namespace between Containers in a Pod
10-
min-kubernetes-server-version: v1.10
119
reviewers:
1210
- verb
1311
- yujuhong
@@ -19,31 +17,25 @@ weight: 160
1917

2018
<!-- overview -->
2119

22-
{{< feature-state state="stable" for_k8s_version="v1.17" >}}
23-
2420
<!--
2521
This page shows how to configure process namespace sharing for a pod. When
2622
process namespace sharing is enabled, processes in a container are visible
27-
to all other containers in that pod.
23+
to all other containers in the same pod.
2824
-->
29-
此页面展示如何为 pod 配置进程命名空间共享。
30-
当启用进程命名空间共享时,容器中的进程对该 pod 中的所有其他容器都是可见的。
25+
此页面展示如何为 Pod 配置进程命名空间共享。
26+
当启用进程命名空间共享时,容器中的进程对同一 Pod 中的所有其他容器都是可见的。
3127

3228
<!--
3329
You can use this feature to configure cooperating containers, such as a log
3430
handler sidecar container, or to troubleshoot container images that don't
3531
include debugging utilities like a shell.
3632
-->
37-
你可以使用此功能来配置协作容器,比如日志处理 sidecar 容器,或者对那些不包含诸如 shell 等调试实用工具的镜像进行故障排查。
38-
39-
33+
你可以使用此功能来配置协作容器,比如日志处理 sidecar 容器,
34+
或者对那些不包含诸如 shell 等调试实用工具的镜像进行故障排查。
4035

4136
## {{% heading "prerequisites" %}}
4237

43-
44-
{{< include "task-tutorial-prereqs.md" >}} {{< version-check >}}
45-
46-
38+
{{< include "task-tutorial-prereqs.md" >}}
4739

4840
<!-- steps -->
4941

@@ -53,68 +45,85 @@ include debugging utilities like a shell.
5345
## 配置 Pod
5446

5547
<!--
56-
Process Namespace Sharing is enabled using the `ShareProcessNamespace` field of
57-
`v1.PodSpec`. For example:
48+
Process namespace sharing is enabled using the `shareProcessNamespace` field of
49+
`.spec` for a Pod. For example:
5850
-->
59-
进程命名空间共享使用 `v1.PodSpec` 中的 `ShareProcessNamespace` 字段启用。例如:
51+
使用 Pod `.spec` 中的 `shareProcessNamespace` 字段可以启用进程命名空间共享。例如:
6052

6153
{{< codenew file="pods/share-process-namespace.yaml" >}}
6254

6355
<!--
6456
1. Create the pod `nginx` on your cluster:
57+
-->
58+
1. 在集群中创建 `nginx` Pod:
6559

66-
```shell
67-
kubectl apply -f https://k8s.io/examples/pods/share-process-namespace.yaml
68-
```
60+
```shell
61+
kubectl apply -f https://k8s.io/examples/pods/share-process-namespace.yaml
62+
```
6963

64+
<!--
7065
1. Attach to the `shell` container and run `ps`:
66+
-->
67+
2. 获取容器 `shell`,执行 `ps`
68+
69+
```shell
70+
kubectl attach -it nginx -c shell
71+
```
72+
73+
<!--
74+
If you don't see a command prompt, try pressing enter. In the container shell:
75+
76+
```shell
77+
# run this inside the "shell" container
78+
ps ax
79+
```
80+
-->
81+
如果没有看到命令提示符,请按 enter 回车键。在容器 shell 中:
82+
83+
```shell
84+
# 在 “shell” 容器中运行以下命令
85+
ps ax
86+
```
87+
88+
<!--
89+
The output is similar to this:
90+
-->
91+
输出类似于:
92+
93+
```none
94+
PID USER TIME COMMAND
95+
1 root 0:00 /pause
96+
8 root 0:00 nginx: master process nginx -g daemon off;
97+
14 101 0:00 nginx: worker process
98+
15 root 0:00 sh
99+
21 root 0:00 ps ax
100+
```
71101

72-
```shell
73-
kubectl attach -it nginx -c shell
74-
```
75-
76-
If you don't see a command prompt, try pressing enter.
77-
78-
```
79-
/ # ps ax
80-
PID USER TIME COMMAND
81-
1 root 0:00 /pause
82-
8 root 0:00 nginx: master process nginx -g daemon off;
83-
14 101 0:00 nginx: worker process
84-
15 root 0:00 sh
85-
21 root 0:00 ps ax
86-
```
87-
-->
88-
1. 在集群中创建 `nginx` pod:
89-
90-
```shell
91-
kubectl apply -f https://k8s.io/examples/pods/share-process-namespace.yaml
92-
```
93-
1. 获取容器 `shell`,执行 `ps`
94-
95-
```shell
96-
kubectl attach -it nginx -c shell
97-
```
98-
如果没有看到命令提示符,请按 enter 回车键。
99-
100-
```
101-
/ # ps ax
102-
PID USER TIME COMMAND
103-
1 root 0:00 /pause
104-
8 root 0:00 nginx: master process nginx -g daemon off;
105-
14 101 0:00 nginx: worker process
106-
15 root 0:00 sh
107-
21 root 0:00 ps ax
108-
```
109102
<!--
110103
You can signal processes in other containers. For example, send `SIGHUP` to
111-
nginx to restart the worker process. This requires the `SYS_PTRACE` capability.
104+
`nginx` to restart the worker process. This requires the `SYS_PTRACE` capability.
105+
106+
```shell
107+
# run this inside the "shell" container
108+
kill -HUP 8 # change "8" to match the PID of the nginx leader process, if necessary
109+
ps ax
110+
```
112111
-->
113-
你可以在其他容器中对进程发出信号。例如,发送 `SIGHUP` 到 nginx 以重启工作进程。这需要 `SYS_PTRACE` 功能。
112+
你可以在其他容器中对进程发出信号。例如,发送 `SIGHUP``nginx` 以重启工作进程。
113+
此操作需要 `SYS_PTRACE` 权能。
114114

115+
```shell
116+
# 在 “shell” 容器中运行以下命令
117+
kill -HUP 8 # 如有必要,更改 “8” 以匹配 nginx 领导进程的 PID
118+
ps ax
115119
```
116-
/ # kill -HUP 8
117-
/ # ps ax
120+
121+
<!--
122+
The output is similar to this:
123+
-->
124+
输出类似于:
125+
126+
```none
118127
PID USER TIME COMMAND
119128
1 root 0:00 /pause
120129
8 root 0:00 nginx: master process nginx -g daemon off;
@@ -124,14 +133,29 @@ PID USER TIME COMMAND
124133
```
125134

126135
<!--
127-
It's even possible to access another container image using the
136+
It's even possible to access the file system of another container using the
128137
`/proc/$pid/root` link.
138+
139+
```shell
140+
# run this inside the "shell" container
141+
# change "8" to the PID of the Nginx process, if necessary
142+
head /proc/8/root/etc/nginx/nginx.conf
143+
```
129144
-->
130-
甚至可以使用 `/proc/$pid/root` 链接访问另一个容器镜像
145+
甚至可以使用 `/proc/$pid/root` 链接访问另一个容器的文件系统
131146

147+
```shell
148+
# 在 “shell” 容器中运行以下命令
149+
# 如有必要,更改 “8” 为 Nginx 进程的 PID
150+
head /proc/8/root/etc/nginx/nginx.conf
132151
```
133-
/ # head /proc/8/root/etc/nginx/nginx.conf
134152

153+
<!--
154+
The output is similar to this:
155+
-->
156+
输出类似于:
157+
158+
```none
135159
user nginx;
136160
worker_processes 1;
137161
@@ -143,45 +167,45 @@ events {
143167
worker_connections 1024;
144168
```
145169

146-
147-
148170
<!-- discussion -->
149171

150172
<!--
151-
## Understanding Process Namespace Sharing
173+
## Understanding process namespace sharing
152174
-->
153175
## 理解进程命名空间共享
154176

155177
<!--
156178
Pods share many resources so it makes sense they would also share a process
157-
namespace. Some container images may expect to be isolated from other
158-
containers, though, so it's important to understand these differences:
179+
namespace. Some containers may expect to be isolated from others, though,
180+
so it's important to understand the differences:
159181
-->
160182
Pod 共享许多资源,因此它们共享进程命名空间是很有意义的。
161-
不过,有些容器镜像可能希望与其他容器隔离,因此了解这些差异很重要:
183+
不过,有些容器可能希望与其他容器隔离,因此了解这些差异很重要:
162184

163185
<!--
164-
1. **The container process no longer has PID 1.** Some container images refuse
186+
1. **The container process no longer has PID 1.** Some containers refuse
165187
to start without PID 1 (for example, containers using `systemd`) or run
166188
commands like `kill -HUP 1` to signal the container process. In pods with a
167-
shared process namespace, `kill -HUP 1` will signal the pod sandbox.
168-
(`/pause` in the above example.)
189+
shared process namespace, `kill -HUP 1` will signal the pod sandbox
190+
(`/pause` in the above example).
191+
-->
192+
1. **容器进程不再具有 PID 1。** 在没有 PID 1 的情况下,一些容器拒绝启动
193+
(例如,使用 `systemd` 的容器),或者拒绝执行 `kill -HUP 1` 之类的命令来通知容器进程。
194+
在具有共享进程命名空间的 Pod 中,`kill -HUP 1` 将通知 Pod 沙箱(在上面的例子中是 `/pause`)。
169195

196+
<!--
170197
1. **Processes are visible to other containers in the pod.** This includes all
171198
information visible in `/proc`, such as passwords that were passed as arguments
172199
or environment variables. These are protected only by regular Unix permissions.
200+
-->
201+
2. **进程对 Pod 中的其他容器可见。** 这包括 `/proc` 中可见的所有信息,
202+
例如作为参数或环境变量传递的密码。这些仅受常规 Unix 权限的保护。
173203

204+
<!--
174205
1. **Container filesystems are visible to other containers in the pod through the
175206
`/proc/$pid/root` link.** This makes debugging easier, but it also means
176207
that filesystem secrets are protected only by filesystem permissions.
177208
-->
178-
179-
1. **容器进程不再具有 PID 1。** 在没有 PID 1 的情况下,一些容器镜像拒绝启动(例如,使用 `systemd` 的容器),或者拒绝执行 `kill -HUP 1` 之类的命令来通知容器进程。在具有共享进程命名空间的 pod 中,`kill -HUP 1` 将通知 pod 沙箱(在上面的例子中是 `/pause`)。
180-
181-
2. **进程对 pod 中的其他容器可见。** 这包括 `/proc` 中可见的所有信息,例如作为参数或环境变量传递的密码。这些仅受常规 Unix 权限的保护。
182-
183-
3. **容器文件系统通过 `/proc/$pid/root` 链接对 pod 中的其他容器可见。** 这使调试更加容易,但也意味着文件系统安全性只受文件系统权限的保护。
184-
185-
186-
209+
3. **容器文件系统通过 `/proc/$pid/root` 链接对 Pod 中的其他容器可见。** 这使调试更加容易,
210+
但也意味着文件系统安全性只受文件系统权限的保护。
187211

0 commit comments

Comments
 (0)