[zh-cn] Update share-process-namespace.md

Signed-off-by: Guangwen Feng <fenggw-fnst@fujitsu.com>
This commit is contained in:
Guangwen Feng
2022-06-29 10:52:53 +08:00
parent 136902bd15
commit 84289e9145
@@ -1,13 +1,11 @@
--- ---
title: 在 Pod 中的容器之间共享进程命名空间 title: 在 Pod 中的容器之间共享进程命名空间
min-kubernetes-server-version: v1.10
content_type: task content_type: task
weight: 160 weight: 160
--- ---
<!-- <!--
--- ---
title: Share Process Namespace between Containers in a Pod title: Share Process Namespace between Containers in a Pod
min-kubernetes-server-version: v1.10
reviewers: reviewers:
- verb - verb
- yujuhong - yujuhong
@@ -19,31 +17,25 @@ weight: 160
<!-- overview --> <!-- overview -->
{{< feature-state state="stable" for_k8s_version="v1.17" >}}
<!-- <!--
This page shows how to configure process namespace sharing for a pod. When This page shows how to configure process namespace sharing for a pod. When
process namespace sharing is enabled, processes in a container are visible process namespace sharing is enabled, processes in a container are visible
to all other containers in that pod. to all other containers in the same pod.
--> -->
此页面展示如何为 pod 配置进程命名空间共享。 此页面展示如何为 Pod 配置进程命名空间共享。
当启用进程命名空间共享时,容器中的进程对该 pod 中的所有其他容器都是可见的。 当启用进程命名空间共享时,容器中的进程对同一 Pod 中的所有其他容器都是可见的。
<!-- <!--
You can use this feature to configure cooperating containers, such as a log You can use this feature to configure cooperating containers, such as a log
handler sidecar container, or to troubleshoot container images that don't handler sidecar container, or to troubleshoot container images that don't
include debugging utilities like a shell. include debugging utilities like a shell.
--> -->
你可以使用此功能来配置协作容器,比如日志处理 sidecar 容器,或者对那些不包含诸如 shell 等调试实用工具的镜像进行故障排查。 你可以使用此功能来配置协作容器,比如日志处理 sidecar 容器,
或者对那些不包含诸如 shell 等调试实用工具的镜像进行故障排查。
## {{% heading "prerequisites" %}} ## {{% heading "prerequisites" %}}
{{< include "task-tutorial-prereqs.md" >}}
{{< include "task-tutorial-prereqs.md" >}} {{< version-check >}}
<!-- steps --> <!-- steps -->
@@ -53,68 +45,85 @@ include debugging utilities like a shell.
## 配置 Pod ## 配置 Pod
<!-- <!--
Process Namespace Sharing is enabled using the `ShareProcessNamespace` field of Process namespace sharing is enabled using the `shareProcessNamespace` field of
`v1.PodSpec`. For example: `.spec` for a Pod. For example:
--> -->
进程命名空间共享使用 `v1.PodSpec` 中的 `ShareProcessNamespace` 字段启用。例如: 使用 Pod `.spec` 中的 `shareProcessNamespace` 字段可以启用进程命名空间共享。例如:
{{< codenew file="pods/share-process-namespace.yaml" >}} {{< codenew file="pods/share-process-namespace.yaml" >}}
<!-- <!--
1. Create the pod `nginx` on your cluster: 1. Create the pod `nginx` on your cluster:
```shell
kubectl apply -f https://k8s.io/examples/pods/share-process-namespace.yaml
```
1. Attach to the `shell` container and run `ps`:
```shell
kubectl attach -it nginx -c shell
```
If you don't see a command prompt, try pressing enter.
```
/ # ps ax
PID USER TIME COMMAND
1 root 0:00 /pause
8 root 0:00 nginx: master process nginx -g daemon off;
14 101 0:00 nginx: worker process
15 root 0:00 sh
21 root 0:00 ps ax
```
--> -->
1. 在集群中创建 `nginx` pod 1. 在集群中创建 `nginx` Pod
```shell ```shell
kubectl apply -f https://k8s.io/examples/pods/share-process-namespace.yaml kubectl apply -f https://k8s.io/examples/pods/share-process-namespace.yaml
``` ```
1. 获取容器 `shell`,执行 `ps`
```shell <!--
kubectl attach -it nginx -c shell 1. Attach to the `shell` container and run `ps`:
``` -->
如果没有看到命令提示符,请按 enter 回车键。 2. 获取容器 `shell`,执行 `ps`
```shell
kubectl attach -it nginx -c shell
```
<!--
If you don't see a command prompt, try pressing enter. In the container shell:
```shell
# run this inside the "shell" container
ps ax
```
-->
如果没有看到命令提示符,请按 enter 回车键。在容器 shell 中:
```shell
# 在 “shell” 容器中运行以下命令
ps ax
```
<!--
The output is similar to this:
-->
输出类似于:
```none
PID USER TIME COMMAND
1 root 0:00 /pause
8 root 0:00 nginx: master process nginx -g daemon off;
14 101 0:00 nginx: worker process
15 root 0:00 sh
21 root 0:00 ps ax
```
```
/ # ps ax
PID USER TIME COMMAND
1 root 0:00 /pause
8 root 0:00 nginx: master process nginx -g daemon off;
14 101 0:00 nginx: worker process
15 root 0:00 sh
21 root 0:00 ps ax
```
<!-- <!--
You can signal processes in other containers. For example, send `SIGHUP` to You can signal processes in other containers. For example, send `SIGHUP` to
nginx to restart the worker process. This requires the `SYS_PTRACE` capability. `nginx` to restart the worker process. This requires the `SYS_PTRACE` capability.
-->
你可以在其他容器中对进程发出信号。例如,发送 `SIGHUP` 到 nginx 以重启工作进程。这需要 `SYS_PTRACE` 功能。
```shell
# run this inside the "shell" container
kill -HUP 8 # change "8" to match the PID of the nginx leader process, if necessary
ps ax
``` ```
/ # kill -HUP 8 -->
/ # ps ax 你可以在其他容器中对进程发出信号。例如,发送 `SIGHUP` 到 `nginx` 以重启工作进程。
此操作需要 `SYS_PTRACE` 权能。
```shell
# 在 “shell” 容器中运行以下命令
kill -HUP 8 # 如有必要,更改 “8” 以匹配 nginx 领导进程的 PID
ps ax
```
<!--
The output is similar to this:
-->
输出类似于:
```none
PID USER TIME COMMAND PID USER TIME COMMAND
1 root 0:00 /pause 1 root 0:00 /pause
8 root 0:00 nginx: master process nginx -g daemon off; 8 root 0:00 nginx: master process nginx -g daemon off;
@@ -124,14 +133,29 @@ PID USER TIME COMMAND
``` ```
<!-- <!--
It's even possible to access another container image using the It's even possible to access the file system of another container using the
`/proc/$pid/root` link. `/proc/$pid/root` link.
-->
甚至可以使用 `/proc/$pid/root` 链接访问另一个容器镜像。
```shell
# run this inside the "shell" container
# change "8" to the PID of the Nginx process, if necessary
head /proc/8/root/etc/nginx/nginx.conf
``` ```
/ # head /proc/8/root/etc/nginx/nginx.conf -->
甚至可以使用 `/proc/$pid/root` 链接访问另一个容器的文件系统。
```shell
# 在 “shell” 容器中运行以下命令
# 如有必要,更改 “8” 为 Nginx 进程的 PID
head /proc/8/root/etc/nginx/nginx.conf
```
<!--
The output is similar to this:
-->
输出类似于:
```none
user nginx; user nginx;
worker_processes 1; worker_processes 1;
@@ -143,45 +167,45 @@ events {
worker_connections 1024; worker_connections 1024;
``` ```
<!-- discussion --> <!-- discussion -->
<!-- <!--
## Understanding Process Namespace Sharing ## Understanding process namespace sharing
--> -->
## 理解进程命名空间共享 ## 理解进程命名空间共享
<!-- <!--
Pods share many resources so it makes sense they would also share a process Pods share many resources so it makes sense they would also share a process
namespace. Some container images may expect to be isolated from other namespace. Some containers may expect to be isolated from others, though,
containers, though, so it's important to understand these differences: so it's important to understand the differences:
--> -->
Pod 共享许多资源,因此它们共享进程命名空间是很有意义的。 Pod 共享许多资源,因此它们共享进程命名空间是很有意义的。
不过,有些容器镜像可能希望与其他容器隔离,因此了解这些差异很重要: 不过,有些容器可能希望与其他容器隔离,因此了解这些差异很重要:
<!-- <!--
1. **The container process no longer has PID 1.** Some container images refuse 1. **The container process no longer has PID 1.** Some containers refuse
to start without PID 1 (for example, containers using `systemd`) or run to start without PID 1 (for example, containers using `systemd`) or run
commands like `kill -HUP 1` to signal the container process. In pods with a commands like `kill -HUP 1` to signal the container process. In pods with a
shared process namespace, `kill -HUP 1` will signal the pod sandbox. shared process namespace, `kill -HUP 1` will signal the pod sandbox
(`/pause` in the above example.) (`/pause` in the above example).
-->
1. **容器进程不再具有 PID 1。** 在没有 PID 1 的情况下,一些容器拒绝启动
(例如,使用 `systemd` 的容器),或者拒绝执行 `kill -HUP 1` 之类的命令来通知容器进程。
在具有共享进程命名空间的 Pod 中,`kill -HUP 1` 将通知 Pod 沙箱(在上面的例子中是 `/pause`)。
<!--
1. **Processes are visible to other containers in the pod.** This includes all 1. **Processes are visible to other containers in the pod.** This includes all
information visible in `/proc`, such as passwords that were passed as arguments information visible in `/proc`, such as passwords that were passed as arguments
or environment variables. These are protected only by regular Unix permissions. or environment variables. These are protected only by regular Unix permissions.
-->
2. **进程对 Pod 中的其他容器可见。** 这包括 `/proc` 中可见的所有信息,
例如作为参数或环境变量传递的密码。这些仅受常规 Unix 权限的保护。
<!--
1. **Container filesystems are visible to other containers in the pod through the 1. **Container filesystems are visible to other containers in the pod through the
`/proc/$pid/root` link.** This makes debugging easier, but it also means `/proc/$pid/root` link.** This makes debugging easier, but it also means
that filesystem secrets are protected only by filesystem permissions. that filesystem secrets are protected only by filesystem permissions.
--> -->
3. **容器文件系统通过 `/proc/$pid/root` 链接对 Pod 中的其他容器可见。** 这使调试更加容易,
1. **容器进程不再具有 PID 1。** 在没有 PID 1 的情况下,一些容器镜像拒绝启动(例如,使用 `systemd` 的容器),或者拒绝执行 `kill -HUP 1` 之类的命令来通知容器进程。在具有共享进程命名空间的 pod 中,`kill -HUP 1` 将通知 pod 沙箱(在上面的例子中是 `/pause` 但也意味着文件系统安全性只受文件系统权限的保护
2. **进程对 pod 中的其他容器可见。** 这包括 `/proc` 中可见的所有信息,例如作为参数或环境变量传递的密码。这些仅受常规 Unix 权限的保护。
3. **容器文件系统通过 `/proc/$pid/root` 链接对 pod 中的其他容器可见。** 这使调试更加容易,但也意味着文件系统安全性只受文件系统权限的保护。