1
1
---
2
2
title : Share Process Namespace between Containers in a Pod
3
- min-kubernetes-server-version : v1.10
4
3
reviewers :
5
4
- verb
6
5
- yujuhong
@@ -11,64 +10,69 @@ weight: 160
11
10
12
11
<!-- overview -->
13
12
14
- {{< feature-state state="stable" for_k8s_version="v1.17" >}}
15
-
16
13
This page shows how to configure process namespace sharing for a pod. When
17
14
process namespace sharing is enabled, processes in a container are visible
18
- to all other containers in that pod.
15
+ to all other containers in the same pod.
19
16
20
17
You can use this feature to configure cooperating containers, such as a log
21
18
handler sidecar container, or to troubleshoot container images that don't
22
19
include debugging utilities like a shell.
23
20
24
-
25
-
26
21
## {{% heading "prerequisites" %}}
27
22
28
-
29
- {{< include "task-tutorial-prereqs.md" >}} {{< version-check >}}
30
-
31
-
23
+ {{< include "task-tutorial-prereqs.md" >}}
32
24
33
25
<!-- steps -->
34
26
35
27
## Configure a Pod
36
28
37
- Process Namespace Sharing is enabled using the ` shareProcessNamespace ` field of
38
- ` v1.PodSpec ` . For example:
29
+ Process namespace sharing is enabled using the ` shareProcessNamespace ` field of
30
+ ` .spec ` for a Pod . For example:
39
31
40
32
{{< codenew file="pods/share-process-namespace.yaml" >}}
41
33
42
34
1 . Create the pod ` nginx ` on your cluster:
43
35
44
- ``` shell
45
- kubectl apply -f https://k8s.io/examples/pods/share-process-namespace.yaml
46
- ```
36
+ ``` shell
37
+ kubectl apply -f https://k8s.io/examples/pods/share-process-namespace.yaml
38
+ ```
47
39
48
40
1 . Attach to the ` shell ` container and run ` ps ` :
49
41
50
- ` ` ` shell
51
- kubectl attach -it nginx -c shell
52
- ` ` `
42
+ ``` shell
43
+ kubectl attach -it nginx -c shell
44
+ ```
45
+
46
+ If you don't see a command prompt, try pressing enter. In the container shell:
47
+
48
+ ``` shell
49
+ # run this inside the "shell" container
50
+ ps ax
51
+ ```
53
52
54
- If you don ' t see a command prompt, try pressing enter.
53
+ The output is similar to this:
55
54
56
- ```
57
- / # ps ax
58
- PID USER TIME COMMAND
59
- 1 root 0:00 /pause
60
- 8 root 0:00 nginx: master process nginx -g daemon off;
61
- 14 101 0:00 nginx: worker process
62
- 15 root 0:00 sh
63
- 21 root 0:00 ps ax
64
- ```
55
+ ``` none
56
+ PID USER TIME COMMAND
57
+ 1 root 0:00 /pause
58
+ 8 root 0:00 nginx: master process nginx -g daemon off;
59
+ 14 101 0:00 nginx: worker process
60
+ 15 root 0:00 sh
61
+ 21 root 0:00 ps ax
62
+ ```
65
63
66
64
You can signal processes in other containers. For example, send ` SIGHUP ` to
67
- nginx to restart the worker process. This requires the `SYS_PTRACE` capability.
65
+ ` nginx ` to restart the worker process. This requires the ` SYS_PTRACE ` capability.
68
66
67
+ ``` shell
68
+ # run this inside the "shell" container
69
+ kill -HUP 8 # change "8" to match the PID of the nginx leader process, if necessary
70
+ ps ax
69
71
```
70
- / # kill -HUP 8
71
- / # ps ax
72
+
73
+ The output is similar to this:
74
+
75
+ ``` none
72
76
PID USER TIME COMMAND
73
77
1 root 0:00 /pause
74
78
8 root 0:00 nginx: master process nginx -g daemon off;
@@ -77,12 +81,18 @@ PID USER TIME COMMAND
77
81
23 root 0:00 ps ax
78
82
```
79
83
80
- It' s even possible to access another container image using the
84
+ It's even possible to access the file system of another container using the
81
85
` /proc/$pid/root ` link.
82
86
87
+ ``` shell
88
+ # run this inside the "shell" container
89
+ # change "8" to the PID of the Nginx process, if necessary
90
+ head /proc/8/root/etc/nginx/nginx.conf
83
91
```
84
- / # head /proc/8/root/etc/nginx/nginx.conf
85
92
93
+ The output is similar to this:
94
+
95
+ ``` none
86
96
user nginx;
87
97
worker_processes 1;
88
98
@@ -94,21 +104,19 @@ events {
94
104
worker_connections 1024;
95
105
```
96
106
97
-
98
-
99
107
<!-- discussion -->
100
108
101
- ## Understanding Process Namespace Sharing
109
+ ## Understanding process namespace sharing
102
110
103
111
Pods share many resources so it makes sense they would also share a process
104
- namespace. Some container images may expect to be isolated from other
105
- containers, though, so it's important to understand these differences:
112
+ namespace. Some containers may expect to be isolated from others, though,
113
+ so it's important to understand the differences:
106
114
107
- 1. **The container process no longer has PID 1.** Some container images refuse
115
+ 1 . ** The container process no longer has PID 1.** Some containers refuse
108
116
to start without PID 1 (for example, containers using ` systemd ` ) or run
109
117
commands like ` kill -HUP 1 ` to signal the container process. In pods with a
110
- shared process namespace, `kill -HUP 1` will signal the pod sandbox.
111
- (`/pause` in the above example.)
118
+ shared process namespace, ` kill -HUP 1 ` will signal the pod sandbox
119
+ (` /pause ` in the above example).
112
120
113
121
1 . ** Processes are visible to other containers in the pod.** This includes all
114
122
information visible in ` /proc ` , such as passwords that were passed as arguments
@@ -118,6 +126,3 @@ containers, though, so it's important to understand these differences:
118
126
` /proc/$pid/root ` link.** This makes debugging easier, but it also means
119
127
that filesystem secrets are protected only by filesystem permissions.
120
128
121
-
122
-
123
-
0 commit comments