Skip to content

Commit 12f51b0

Browse files
committed
Create a task describing Pod process namespace sharing
1 parent 279e227 commit 12f51b0

File tree

3 files changed

+137
-0
lines changed

3 files changed

+137
-0
lines changed

_data/tasks.yml

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ toc:
2929
- docs/tasks/configure-pod-container/configure-pod-initialization.md
3030
- docs/tasks/configure-pod-container/attach-handler-lifecycle-event.md
3131
- docs/tasks/configure-pod-container/configure-pod-configmap.md
32+
- docs/tasks/configure-pod-container/share-process-namespace.md
3233
- docs/tools/kompose/user-guide.md
3334

3435
- title: Inject Data Into Applications
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
---
2+
title: Share Process Namespace between Containers in a Pod
3+
min-kubernetes-server-version: 1.10
4+
approvers:
5+
- dawnchen
6+
- verb
7+
---
8+
9+
{% capture overview %}
10+
11+
{% include feature-state-alpha.md %}
12+
13+
This page shows how to configure process namespace sharing for a pod. When
14+
process namespace sharing is enabled, processes in a container will be visible
15+
to all other containers in that pod.
16+
17+
This can be useful for cooperating containers, such as a log handler sidecar
18+
container, or troubleshooting container images that don't include debugging
19+
utilities like a shell.
20+
21+
{% endcapture %}
22+
23+
{% capture prerequisites %}
24+
25+
* {% include task-tutorial-prereqs.md %}
26+
* A special **alpha** feature gate `PodShareProcessNamespace` has to be set to
27+
true across the system: `--feature-gates=PodShareProcessNamespace=true`.
28+
29+
{% endcapture %}
30+
31+
{% capture steps %}
32+
33+
## Configure a Pod
34+
35+
Process Namespace Sharing is enabled using the `ShareProcessNamespace` field of
36+
`v1.PodSpec`. For example:
37+
38+
{% include code.html language="yaml" file="share-process-namespace.yaml" ghlink="/docs/tasks/configure-pod-container/share-process-namespace.yaml" %}
39+
40+
1. Create the pod `nginx` on your cluster:
41+
42+
```shell
43+
$ kubectl create -f https://k8s.io/docs/tasks/configure-pod-container/share-process-namespace.yaml
44+
```
45+
46+
1. Attach to the `shell` container and run `ps`:
47+
48+
```shell
49+
$ kc attach -it nginx -c shell
50+
If you don't see a command prompt, try pressing enter.
51+
/ # ps ax
52+
PID USER TIME COMMAND
53+
1 root 0:00 /pause
54+
8 root 0:00 nginx: master process nginx -g daemon off;
55+
14 101 0:00 nginx: worker process
56+
15 root 0:00 sh
57+
21 root 0:00 ps ax
58+
```
59+
60+
1. It's possible to signal processes in other containers. Sending `SIGHUP` to
61+
nginx causes it to restart the worker process (this requires the `SYS_PTRACE`
62+
capability):
63+
64+
```shell
65+
/ # kill -HUP 8
66+
/ # ps ax
67+
PID USER TIME COMMAND
68+
1 root 0:00 /pause
69+
8 root 0:00 nginx: master process nginx -g daemon off;
70+
15 root 0:00 sh
71+
22 101 0:00 nginx: worker process
72+
23 root 0:00 ps ax
73+
```
74+
75+
1. It's even possible to access another container image using the
76+
`/proc/$pid/root` link:
77+
78+
```shell
79+
/ # head /proc/8/root/etc/nginx/nginx.conf
80+
81+
user nginx;
82+
worker_processes 1;
83+
84+
error_log /var/log/nginx/error.log warn;
85+
pid /var/run/nginx.pid;
86+
87+
88+
events {
89+
worker_connections 1024;
90+
```
91+
92+
{% endcapture %}
93+
94+
{% capture discussion %}
95+
96+
## Understanding Process Namespace Sharing
97+
98+
Pods share many resources so it makes sense they would also share a process
99+
namespace. Some container images may expect to be isolated from other
100+
containers, though, so it's important to understand these differences:
101+
102+
1. **The container process no longer has PID 1.** Some container images refuse
103+
to start without PID 1 (e.g. containers using `systemd`) or run commands like
104+
`kill -HUP 1` to signal the container process. In pods with a shared process
105+
namespace, `kill -HUP 1` will instead signal the pod sandbox. (`/pause`
106+
in the above example.)
107+
108+
1. **Processes are visible to other containers in the pod.** This includes all
109+
information visible in `/proc`, such as passwords that were passed as arguments
110+
or environment variables. These will be protected only by regular Unix
111+
permissions.
112+
113+
1. **Container filesystems are visible to other containers in the pod through the
114+
`/proc/$pid/root` link.** This makes debugging easier, but it also means
115+
that secrets are protected only by filesystem permissions.
116+
117+
{% endcapture %}
118+
119+
{% include templates/task.md %}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
apiVersion: v1
2+
kind: Pod
3+
metadata:
4+
name: nginx
5+
spec:
6+
shareProcessNamespace: true
7+
containers:
8+
- name: nginx
9+
image: nginx
10+
- name: shell
11+
image: busybox
12+
securityContext:
13+
capabilities:
14+
add:
15+
- SYS_PTRACE
16+
stdin: true
17+
tty: true

0 commit comments

Comments
 (0)