Skip to content

Commit 50eb91f

Browse files
committed
Create a task describing Pod process namespace sharing
1 parent 5829739 commit 50eb91f

File tree

4 files changed

+131
-0
lines changed

4 files changed

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