Skip to content

Commit 3517feb

Browse files
authored
Merge pull request #54111 from aireilly/encapsulated-namespaces
TELCODOCS-640 updates
2 parents dc8f03f + ad935f3 commit 3517feb

File tree

6 files changed

+133
-106
lines changed

6 files changed

+133
-106
lines changed

modules/enabling_encapsulation.adoc renamed to modules/enabling-encapsulation.adoc

Lines changed: 46 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
// Module included in the following assemblies:
22
//
33
// * scalability_and_performance/optimizing-cpu-usage.adoc
4+
45
:_content-type: PROCEDURE
56
[id="enabling-encapsulation_{context}"]
67
= Configuring mount namespace encapsulation
78

89
You can configure mount namespace encapsulation so that a cluster runs with less resource overhead.
9-
Because mount namespace encapsulation is a Technology Preview feature, it is disabled by default, and must be manually enabled.
10+
11+
[NOTE]
12+
====
13+
Mount namespace encapsulation is a Technology Preview feature and it is disabled by default. To use it, you must enable the feature manually.
14+
====
1015

1116
.Prerequisites
1217

@@ -16,42 +21,40 @@ Because mount namespace encapsulation is a Technology Preview feature, it is dis
1621
1722
.Procedure
1823

19-
. Create a file called `mount_namespace_config.yaml` with the following YAML to control whether encapsulation is enabled or disabled:
24+
. Create a file called `mount_namespace_config.yaml` with the following YAML:
2025
+
2126
[source,yaml]
2227
----
23-
apiVersion: machineconfiguration.openshift.io/v1
24-
kind: MachineConfig
25-
metadata:
26-
labels:
27-
machineconfiguration.openshift.io/role: master
28-
name: 99-kubens-master
29-
spec:
30-
config:
31-
ignition:
32-
version: 3.2.0
33-
systemd:
34-
units:
35-
- enabled: true <1>
36-
name: kubens.service
37-
---
38-
apiVersion: machineconfiguration.openshift.io/v1
39-
kind: MachineConfig
40-
metadata:
41-
labels:
42-
machineconfiguration.openshift.io/role: worker
43-
name: 99-kubens-worker
44-
spec:
45-
config:
46-
ignition:
47-
version: 3.2.0
48-
systemd:
49-
units:
50-
- enabled: true <2>
51-
name: kubens.service
52-
----
53-
<1> If `enabled` is set to true, encapsulation is in effect for all control plane nodes (in the role of `master`) .
54-
<2> If `enabled` is set to true, encapsulation is in effect for all compute nodes (in the role of `worker`).
28+
apiVersion: machineconfiguration.openshift.io/v1
29+
kind: MachineConfig
30+
metadata:
31+
labels:
32+
machineconfiguration.openshift.io/role: master
33+
name: 99-kubens-master
34+
spec:
35+
config:
36+
ignition:
37+
version: 3.2.0
38+
systemd:
39+
units:
40+
- enabled: true
41+
name: kubens.service
42+
---
43+
apiVersion: machineconfiguration.openshift.io/v1
44+
kind: MachineConfig
45+
metadata:
46+
labels:
47+
machineconfiguration.openshift.io/role: worker
48+
name: 99-kubens-worker
49+
spec:
50+
config:
51+
ignition:
52+
version: 3.2.0
53+
systemd:
54+
units:
55+
- enabled: true
56+
name: kubens.service
57+
----
5558

5659
. Apply the mount namespace `MachineConfig` CR by running the following command:
5760
+
@@ -98,9 +101,9 @@ machineconfigpool.machineconfiguration.openshift.io/worker condition met
98101

99102
.Verification
100103

101-
To establish whether or not encapsulation is enabled, run the following commands:
104+
To verify encapsulation for a cluster host, run the following commands:
102105

103-
. Open a debug shell to the cluster host.
106+
. Open a debug shell to the cluster host:
104107
+
105108
[source,terminal]
106109
----
@@ -114,7 +117,7 @@ $ oc debug node/<node_name>
114117
sh-4.4# chroot /host
115118
----
116119

117-
. Check systemd mount namespace:
120+
. Check the systemd mount namespace:
118121
+
119122
[source,terminal]
120123
----
@@ -140,7 +143,7 @@ sh-4.4# readlink /proc/$(pgrep kubelet)/ns/mnt
140143
mnt:[4026531840]
141144
----
142145

143-
. Check CRI-O mount namespace:
146+
. Check the CRI-O mount namespace:
144147
+
145148
[source,terminal]
146149
----
@@ -152,9 +155,8 @@ sh-4.4# readlink /proc/$(pgrep crio)/ns/mnt
152155
----
153156
mnt:[4026531840]
154157
----
155-
+
156-
These commands return the mount namespaces associated with systemd, kubelet and the container runtime. In {product-title}, the container runtime is CRI-O.
157-
+
158-
Encapsulation is in effect if kubelet and CRI-O have a different mount namespace location to systemd.
159-
This is the case in the above example.
160-
Encapsulation is not in effect if all three namespaces are in the same mount namespace location.
158+
159+
These commands return the mount namespaces associated with systemd, kubelet, and the container runtime. In {product-title}, the container runtime is CRI-O.
160+
161+
Encapsulation is in effect if systemd is in a different mount namespace to kubelet and CRI-O as in the above example.
162+
Encapsulation is not in effect if all three processes are in the same mount namespace.
Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,41 @@
11
// Module included in the following assemblies:
22
//
3-
// * scalability_and_performance/optimizing-cpu-usage
3+
// * scalability_and_performance/optimizing-cpu-usage.adoc
4+
45
:_content-type: CONCEPT
56
[id="optimizing-cpu-usage_{context}"]
67
= Encapsulating mount namespaces
78

89
Mount namespaces are used to isolate mount points so that processes in different namespaces cannot view each others' files. Encapsulation is the process of moving Kubernetes mount namespaces to an alternative location where they will not be constantly scanned by the host operating system.
910

10-
The host operating system uses systemd to constantly scan all mount namespaces: both the standard Linux mounts and the numerous mounts that Kubernetes uses to operate. The current implementation of kubelet and CRI-O both use the top-level namespace for all container runtime and kubelet mountpoints. However, encapsulating these container-specific mountpoints in a private namespace reduces systemd overhead with no difference in functionality. Using a separate mount namespace for both CRI-O and kubelet can encapsulate container-specific mounts from any systemd or other host OS interaction.
11+
The host operating system uses systemd to constantly scan all mount namespaces: both the standard Linux mounts and the numerous mounts that Kubernetes uses to operate. The current implementation of kubelet and CRI-O both use the top-level namespace for all container runtime and kubelet mount points. However, encapsulating these container-specific mount points in a private namespace reduces systemd overhead with no difference in functionality. Using a separate mount namespace for both CRI-O and kubelet can encapsulate container-specific mounts from any systemd or other host operating system interaction.
1112

1213
This ability to potentially achieve major CPU optimization is now available to all {product-title} administrators. Encapsulation can also improve security by storing Kubernetes-specific mount points in a location safe from inspection by unprivileged users.
1314

1415
The following diagrams illustrate a Kubernetes installation before and after encapsulation. Both scenarios show example containers which have mount propagation settings of bidirectional, host-to-container, and none.
1516

1617
image::before-k8s-mount-propagation.png[Before encapsulation]
1718

18-
Here we see systemd, host OS processes, kubelet, and the container runtime sharing a single mount namespace.
19+
Here we see systemd, host operating system processes, kubelet, and the container runtime sharing a single mount namespace.
1920

20-
* systemd, host OS processes, kubelet, and the container runtime each have access to and visibility of all mount points.
21+
* systemd, host operating system processes, kubelet, and the container runtime each have access to and visibility of all mount points.
2122
22-
* Container 1, configured with bidirectional mount propagation, can access systemd and host mounts, kubelet and CRI-O mounts. A mount originating in Container 1, such as `/run/a` is visible to systemd, host OS processes, kubelet, container runtime, and other containers with host-to-container or bidirectional mount propagation configured (as in Container 2).
23+
* Container 1, configured with bidirectional mount propagation, can access systemd and host mounts, kubelet and CRI-O mounts. A mount originating in Container 1, such as `/run/a` is visible to systemd, host operating system processes, kubelet, container runtime, and other containers with host-to-container or bidirectional mount propagation configured (as in Container 2).
2324
2425
* Container 2, configured with host-to-container mount propagation, can access systemd and host mounts, kubelet and CRI-O mounts. A mount originating in Container 2, such as `/run/b`, is not visible to any other context.
2526
2627
* Container 3, configured with no mount propagation, has no visibility of external mount points. A mount originating in Container 3, such as `/run/c`, is not visible to any other context.
2728
28-
2929
The following diagram illustrates the system state after encapsulation.
3030

3131
image::after-k8s-mount-propagation.png[After encapsulation]
3232

33-
* The main systemd process is no longer devoted to unnecessary scanning of Kubernetes-specific mount points. It only monitors systemd-specific and host mountpoints.
33+
* The main systemd process is no longer devoted to unnecessary scanning of Kubernetes-specific mount points. It only monitors systemd-specific and host mount points.
3434
35-
* The host OS processes can access only the systemd and host mountpoints.
35+
* The host operating system processes can access only the systemd and host mount points.
3636
37-
* Using a separate mount namespace for both CRI-O and kubelet completely separates all container-specific mounts away from any systemd or other host OS interaction whatsoever.
37+
* Using a separate mount namespace for both CRI-O and kubelet completely separates all container-specific mounts away from any systemd or other host operating system interaction whatsoever.
3838
39-
* The behavior of Container 1 is unchanged, except a mount it creates such as `/run/a` is no longer visible to systemd or host OS processes. It is still visible to kubelet, CRI-O, and other containers with host-to-container or bidirectional mount propagation configured (like Container 2).
39+
* The behavior of Container 1 is unchanged, except a mount it creates such as `/run/a` is no longer visible to systemd or host operating system processes. It is still visible to kubelet, CRI-O, and other containers with host-to-container or bidirectional mount propagation configured (like Container 2).
4040
4141
* The behavior of Container 2 and Container 3 is unchanged.

modules/running_services_with_encapsulation.adoc renamed to modules/running-services-with-encapsulation.adoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
//
33
// * scalability_and_performance/optimizing-cpu-usage.adoc
44
:_content-type: PROCEDURE
5-
[id="running_services_with_encapsulation_{context}"]
5+
[id="running-services-with-encapsulation_{context}"]
66
= Running additional services in the encapsulated namespace
77

8-
Any monitoring tool that relies on the ability to run in the host OS and have visibility of mountpoints created by kubelet, CRI-O, or containers themselves, must enter the container mount namespace to see these mountpoints. The `kubensenter` script that comes with {product-title} executes another command inside the Kubernetes mountpoint and can be used to adapt any existing tools.
8+
Any monitoring tool that relies on the ability to run in the host operating system and have visibility of mount points created by kubelet, CRI-O, or containers themselves, must enter the container mount namespace to see these mount points. The `kubensenter` script that is provided with {product-title} executes another command inside the Kubernetes mount point and can be used to adapt any existing tools.
99

1010
The `kubensenter` script is aware of the state of the mount encapsulation feature status, and is safe to run even if encapsulation is not enabled. In that case the script executes the provided command in the default mount namespace.
1111

modules/supporting-encapsulation.adoc

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
// Module included in the following assemblies:
2+
//
3+
// * scalability_and_performance/optimizing-cpu-usage.adoc
4+
5+
:_content-type: PROCEDURE
6+
[id="supporting-encapsulation_{context}"]
7+
= Inspecting encapsulated namespaces
8+
9+
You can inspect Kubernetes-specific mount points in the cluster host operating system for debugging or auditing purposes by using the `kubensenter` script that is available in {op-system-first}.
10+
11+
SSH shell sessions to the cluster host are in the default namespace.
12+
To inspect Kubernetes-specific mount points in an SSH shell prompt, you need to run the `kubensenter` script as root.
13+
The `kubensenter` script is aware of the state of the mount encapsulation, and is safe to run even if encapsulation is not enabled.
14+
15+
[NOTE]
16+
====
17+
`oc debug` remote shell sessions start inside the Kubernetes namespace by default.
18+
You do not need to run `kubensenter` to inspect mount points when you use `oc debug`.
19+
====
20+
21+
If the encapsulation feature is not enabled, the `kubensenter findmnt` and `findmnt` commands return the same output, regardless of whether they are run in an `oc debug` session or in an SSH shell prompt.
22+
23+
.Prerequisites
24+
25+
* You have installed the OpenShift CLI (`oc`).
26+
27+
* You have logged in as a user with `cluster-admin` privileges.
28+
29+
* You have configured SSH access to the cluster host.
30+
31+
.Procedure
32+
33+
. Open a remote SSH shell to the cluster host. For example:
34+
+
35+
[source,terminal]
36+
----
37+
$ ssh core@<node_name>
38+
----
39+
40+
. Run commands using the provided `kubensenter` script as the root user.
41+
To run a single command inside the Kubernetes namespace, provide the command and any arguments to the `kubensenter` script.
42+
For example, to run the `findmnt` command inside the Kubernetes namespace, run the following command:
43+
+
44+
[source,terminal]
45+
----
46+
[core@control-plane-1 ~]$ sudo kubensenter findmnt
47+
----
48+
+
49+
.Example output
50+
[source,terminal]
51+
----
52+
kubensenter: Autodetect: kubens.service namespace found at /run/kubens/mnt
53+
TARGET SOURCE FSTYPE OPTIONS
54+
/ /dev/sda4[/ostree/deploy/rhcos/deploy/32074f0e8e5ec453e56f5a8a7bc9347eaa4172349ceab9c22b709d9d71a3f4b0.0]
55+
| xfs rw,relatime,seclabel,attr2,inode64,logbufs=8,logbsize=32k,prjquota
56+
shm tmpfs
57+
...
58+
----
59+
60+
. To start a new interactive shell inside the Kubernetes namespace, run the `kubensenter` script without any arguments:
61+
+
62+
[source,terminal]
63+
----
64+
[core@control-plane-1 ~]$ sudo kubensenter
65+
----
66+
+
67+
.Example output
68+
[source,terminal]
69+
----
70+
kubensenter: Autodetect: kubens.service namespace found at /run/kubens/mnt
71+
----

modules/supporting_encapsulation.adoc

Lines changed: 0 additions & 46 deletions
This file was deleted.

scalability_and_performance/optimizing-cpu-usage.adoc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ include::snippets/technology-preview.adoc[]
1313

1414
include::modules/optimizing-by-encapsulation.adoc[leveloffset=+1]
1515

16-
include::modules/enabling_encapsulation.adoc[leveloffset=+1]
16+
include::modules/enabling-encapsulation.adoc[leveloffset=+1]
1717

18-
include::modules/supporting_encapsulation.adoc[leveloffset=+1]
18+
include::modules/supporting-encapsulation.adoc[leveloffset=+1]
1919

20-
include::modules/running_services_with_encapsulation.adoc[leveloffset=+1]
20+
include::modules/running-services-with-encapsulation.adoc[leveloffset=+1]
2121

2222
[role="_additional-resources"]
2323
[id="optimizing-cpu-usage-additional-resources"]
@@ -27,4 +27,4 @@ include::modules/running_services_with_encapsulation.adoc[leveloffset=+1]
2727

2828
* link:https://www.redhat.com/sysadmin/container-namespaces-nsenter[Manage containers in namespaces by using nsenter]
2929

30-
* xref:../rest_api/machine_apis/machineconfig-machineconfiguration-openshift-io-v1.html[MachineConfig]
30+
* xref:../rest_api/machine_apis/machineconfig-machineconfiguration-openshift-io-v1.adoc[MachineConfig]

0 commit comments

Comments
 (0)