Skip to content

Commit 700209b

Browse files
verbk8s-ci-robot
authored andcommitted
Create a task describing Pod process namespace sharing (#7489)
1 parent 5ffc1e2 commit 700209b

File tree

5 files changed

+133
-0
lines changed

5 files changed

+133
-0
lines changed

_data/tasks.yml

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ toc:
3232
- docs/tasks/configure-pod-container/configure-pod-initialization.md
3333
- docs/tasks/configure-pod-container/attach-handler-lifecycle-event.md
3434
- docs/tasks/configure-pod-container/configure-pod-configmap.md
35+
- docs/tasks/configure-pod-container/share-process-namespace.md
3536
- docs/tools/kompose/user-guide.md
3637

3738
- title: Inject Data Into Applications

docs/reference/feature-gates.md

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

test/examples_test.go

+3
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,7 @@ func TestExampleObjectSchemas(t *testing.T) {
414414
"security-context-2": {&api.Pod{}},
415415
"security-context-3": {&api.Pod{}},
416416
"security-context-4": {&api.Pod{}},
417+
"share-process-namespace": {&api.Pod{}},
417418
"task-pv-claim": {&api.PersistentVolumeClaim{}},
418419
"task-pv-pod": {&api.Pod{}},
419420
"task-pv-volume": {&api.PersistentVolume{}},
@@ -589,6 +590,8 @@ func TestExampleObjectSchemas(t *testing.T) {
589590
capabilities.SetForTests(capabilities.Capabilities{
590591
AllowPrivileged: true,
591592
})
593+
// PodShareProcessNamespace needed for example share-process-namespace.yaml
594+
utilfeature.DefaultFeatureGate.Set("PodShareProcessNamespace=true")
592595

593596
for path, expected := range cases {
594597
tested := 0

0 commit comments

Comments
 (0)