Skip to content

Commit 6416a61

Browse files
authored
Merge pull request #45888 from kquinn1204/TELCODOCS-419
Telcodocs 419: Updating Sysctl and creating section on setting interface sysctl values
2 parents e9a1617 + f03225e commit 6416a61

12 files changed

+604
-168
lines changed

_topic_maps/_topic_map.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -983,6 +983,8 @@ Topics:
983983
File: configuring-node-port-service-range
984984
- Name: Configuring IP failover
985985
File: configuring-ipfailover
986+
- Name: Configuring interface-level network sysctls
987+
File: setting-interface-level-network-sysctls
986988
- Name: Using SCTP
987989
File: using-sctp
988990
Distros: openshift-enterprise,openshift-origin
43.2 KB
Loading
43.5 KB
Loading
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
// Module included in the following assemblies:
2+
//
3+
// * nodes/containers/nodes-containers-sysctls.adoc
4+
5+
:_content-type: PROCEDURE
6+
[id="nodes-starting-pod-safe-sysctls_{context}"]
7+
= Starting a pod with safe sysctls
8+
9+
You can set sysctls on pods using the pod's `securityContext`. The `securityContext` applies to all containers in the same pod.
10+
11+
Safe sysctls are allowed by default.
12+
13+
This example uses the pod `securityContext` to set the following safe sysctls:
14+
15+
* `kernel.shm_rmid_forced`
16+
* `net.ipv4.ip_local_port_range`
17+
* `net.ipv4.tcp_syncookies`
18+
* `net.ipv4.ping_group_range`
19+
20+
[WARNING]
21+
====
22+
To avoid destabilizing your operating system, modify sysctl parameters only after you understand their effects.
23+
====
24+
25+
Use this procedure to start a pod with the configured sysctl settings.
26+
[NOTE]
27+
====
28+
In most cases you modify an existing pod definition and add the `securityContext` spec.
29+
====
30+
31+
32+
.Procedure
33+
34+
. Create a YAML file `sysctl_pod.yaml` that defines an example pod and add the `securityContext` spec, as shown in the following example:
35+
+
36+
[source,yaml]
37+
----
38+
apiVersion: v1
39+
kind: Pod
40+
metadata:
41+
name: sysctl-example
42+
namespace: default
43+
spec:
44+
containers:
45+
- name: podexample
46+
image: centos
47+
command: ["bin/bash", "-c", "sleep INF"]
48+
securityContext:
49+
runAsUser: 2000 <1>
50+
runAsGroup: 3000 <2>
51+
allowPrivilegeEscalation: false <3>
52+
capabilities: <4>
53+
drop: ["ALL"]
54+
securityContext:
55+
runAsNonRoot: true <5>
56+
seccompProfile: <6>
57+
type: RuntimeDefault
58+
sysctls:
59+
- name: kernel.shm_rmid_forced
60+
value: "1"
61+
- name: net.ipv4.ip_local_port_range
62+
value: "32770 60666"
63+
- name: net.ipv4.tcp_syncookies
64+
value: "0"
65+
- name: net.ipv4.ping_group_range
66+
value: "0 200000000"
67+
----
68+
<1> `runAsUser` controls which user ID the container is run with.
69+
<2> `runAsGroup` controls which primary group ID the containers is run with.
70+
<3> `allowPrivilegeEscalation` determines if a pod can request to allow privilege escalation. If unspecified, it defaults to true. This boolean directly controls whether the `no_new_privs` flag gets set on the container process.
71+
<4> `capabilities` permit privileged actions without giving full root access. This policy ensures all capabilities are dropped from the pod.
72+
<5> `runAsNonRoot: true` requires that the container will run with a user with any UID other than 0.
73+
<6> `RuntimeDefault` enables the default seccomp profile for a pod or container workload.
74+
75+
. Create the pod by running the following command:
76+
+
77+
[source,terminal]
78+
----
79+
$ oc apply -f sysctl_pod.yaml
80+
----
81+
+
82+
. Verify that the pod is created by running the following command:
83+
+
84+
[source,terminal]
85+
----
86+
$ oc get pod
87+
----
88+
+
89+
.Example output
90+
[source,terminal]
91+
----
92+
NAME READY STATUS RESTARTS AGE
93+
sysctl-example 1/1 Running 0 14s
94+
----
95+
96+
. Log in to the pod by running the following command:
97+
+
98+
[source,terminal]
99+
----
100+
$ oc rsh sysctl-example
101+
----
102+
103+
. Verify the values of the configured sysctl flags. For example, find the value `kernel.shm_rmid_forced` by running the following command:
104+
+
105+
[source,terminal]
106+
----
107+
sh-4.4# sysctl kernel.shm_rmid_forced
108+
----
109+
+
110+
.Expected output
111+
[source,terminal]
112+
----
113+
kernel.shm_rmid_forced = 1
114+
----

modules/nodes-containers-sysctls-about.adoc

Lines changed: 7 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -6,94 +6,17 @@
66
[id="nodes-containers-sysctls-about_{context}"]
77
= About sysctls
88

9-
In Linux, the sysctl interface allows an administrator to modify kernel
10-
parameters at runtime. Parameters are available via the *_/proc/sys/_* virtual
11-
process file system. The parameters cover various subsystems, such as:
9+
In Linux, the sysctl interface allows an administrator to modify kernel parameters at runtime. Parameters are available from the `_/proc/sys/_` virtual process file system. The parameters cover various subsystems, such as:
1210

13-
- kernel (common prefix: *_kernel._*)
14-
- networking (common prefix: *_net._*)
15-
- virtual memory (common prefix: *_vm._*)
16-
- MDADM (common prefix: *_dev._*)
11+
- kernel (common prefix: `_kernel._`)
12+
- networking (common prefix: `_net._`)
13+
- virtual memory (common prefix: `_vm._`)
14+
- MDADM (common prefix: `_dev._`)
1715
18-
More subsystems are described in
19-
link:https://www.kernel.org/doc/Documentation/sysctl/README[Kernel documentation].
16+
More subsystems are described in link:https://www.kernel.org/doc/Documentation/sysctl/README[Kernel documentation].
2017
To get a list of all parameters, run:
2118

2219
[source,terminal]
2320
----
2421
$ sudo sysctl -a
25-
----
26-
27-
[[namespaced-vs-node-level-sysctls]]
28-
== Namespaced versus node-level sysctls
29-
30-
A number of sysctls are _namespaced_ in the Linux kernels. This means that
31-
you can set them independently for each pod on a node. Being namespaced is a
32-
requirement for sysctls to be accessible in a pod context within Kubernetes.
33-
34-
The following sysctls are known to be namespaced:
35-
36-
- *_kernel.shm*_*
37-
- *_kernel.msg*_*
38-
- *_kernel.sem_*
39-
- *_fs.mqueue.*_*
40-
41-
Additionally, most of the sysctls in the *net.** group are known
42-
to be namespaced. Their namespace adoption differs based on the kernel
43-
version and distributor.
44-
45-
Sysctls that are not namespaced are called _node-level_ and must be set
46-
manually by the cluster administrator, either by means of the underlying Linux
47-
distribution of the nodes, such as by modifying the *_/etc/sysctls.conf_* file,
48-
or by using a daemon set with privileged containers. You can use
49-
the Node Tuning Operator to set _node-level_ sysctls.
50-
51-
52-
[NOTE]
53-
====
54-
Consider marking nodes with special sysctls as tainted. Only schedule pods onto
55-
them that need those sysctl settings. Use the taints and toleration feature to mark the nodes.
56-
====
57-
58-
[[safe-vs-unsafe-sysclts]]
59-
== Safe versus unsafe sysctls
60-
61-
Sysctls are grouped into _safe_ and _unsafe_ sysctls.
62-
63-
For a sysctl to be considered safe, it must use proper
64-
namespacing and must be properly isolated between pods on the same
65-
node. This means that if you set a sysctl for one pod it must not:
66-
67-
- Influence any other pod on the node
68-
- Harm the node's health
69-
- Gain CPU or memory resources outside of the resource limits of a pod
70-
71-
{product-title} supports, or whitelists, the following sysctls
72-
in the safe set:
73-
74-
- *_kernel.shm_rmid_forced_*
75-
- *_net.ipv4.ip_local_port_range_*
76-
- *_net.ipv4.tcp_syncookies_*
77-
- *_net.ipv4.ping_group_range_*
78-
79-
All safe sysctls are enabled by default. You can use a sysctl in a pod by modifying
80-
the `Pod` spec.
81-
82-
Any sysctl not whitelisted by {product-title} is considered unsafe for {product-title}.
83-
Note that being namespaced alone is not sufficient for the sysctl to be considered safe.
84-
85-
All unsafe sysctls are disabled by default, and the cluster administrator must
86-
manually enable them on a per-node basis. Pods with disabled unsafe sysctls
87-
are scheduled but do not launch.
88-
89-
[source,terminal]
90-
----
91-
$ oc get pod
92-
----
93-
94-
.Example output
95-
[source,terminal]
96-
----
97-
NAME READY STATUS RESTARTS AGE
98-
hello-pod 0/1 SysctlForbidden 0 14s
99-
----
22+
----

modules/nodes-containers-sysctls-setting.adoc

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,63 +3,63 @@
33
// * nodes/containers/nodes-containers-sysctls.adoc
44

55
:_content-type: PROCEDURE
6-
[id="nodes-containers-sysctls-setting_{context}"]
7-
= Setting sysctls for a pod
6+
[id="nodes-containers-starting-pod-with-unsafe-sysctls_{context}"]
7+
= Starting a pod with unsafe sysctls
88

9-
You can set sysctls on pods using the pod's `securityContext`. The `securityContext`
10-
applies to all containers in the same pod.
9+
A pod with unsafe sysctls fails to launch on any node unless the cluster administrator explicitly enables unsafe sysctls for that node. As with node-level sysctls, use the taints and toleration feature or labels on nodes to schedule those pods onto the right nodes.
1110

12-
Safe sysctls are allowed by default. A pod with unsafe sysctls fails
13-
to launch on any node unless the cluster administrator explicitly enables unsafe sysctls for
14-
that node. As with node-level sysctls, use the taints and toleration feature
15-
or labels on nodes to schedule those pods onto the right nodes.
16-
17-
The following example uses the pod `securityContext` to set a safe sysctl
18-
`kernel.shm_rmid_forced` and two unsafe sysctls, `net.core.somaxconn` and
19-
`kernel.msgmax`. There is no distinction between _safe_ and _unsafe_ sysctls in
20-
the specification.
11+
The following example uses the pod `securityContext` to set a safe sysctl `kernel.shm_rmid_forced` and two unsafe sysctls, `net.core.somaxconn` and `kernel.msgmax`. There is no distinction between _safe_ and _unsafe_ sysctls in the specification.
2112

2213
[WARNING]
2314
====
24-
To avoid destabilizing your operating system, modify sysctl parameters only
25-
after you understand their effects.
15+
To avoid destabilizing your operating system, modify sysctl parameters only after you understand their effects.
2616
====
2717

28-
.Procedure
18+
The following example illustrates what happens when you add safe and unsafe sysctls to a pod specification:
2919

30-
To use safe and unsafe sysctls:
20+
.Procedure
3121

32-
. Modify the YAML file that defines the pod and add the `securityContext` spec, as
33-
shown in the following example:
22+
. Create a YAML file `sysctl-example-unsafe.yaml` that defines an example pod and add the `securityContext` specification, as shown in the following example:
3423
+
3524
[source,yaml]
3625
----
3726
apiVersion: v1
3827
kind: Pod
3928
metadata:
40-
name: sysctl-example
29+
name: sysctl-example-unsafe
4130
spec:
31+
containers:
32+
- name: podexample
33+
image: centos
34+
command: ["bin/bash", "-c", "sleep INF"]
35+
securityContext:
36+
runAsUser: 2000
37+
runAsGroup: 3000
38+
allowPrivilegeEscalation: false
39+
capabilities:
40+
drop: ["ALL"]
4241
securityContext:
42+
runAsNonRoot: true
43+
seccompProfile:
44+
type: RuntimeDefault
4345
sysctls:
4446
- name: kernel.shm_rmid_forced
4547
value: "0"
4648
- name: net.core.somaxconn
4749
value: "1024"
4850
- name: kernel.msgmax
4951
value: "65536"
50-
...
5152
----
5253

53-
. Create the pod:
54+
. Create the pod using the following command:
5455
+
5556
[source,terminal]
5657
----
57-
$ oc apply -f <file-name>.yaml
58+
$ oc apply -f sysctl-example-unsafe.yaml
5859
----
59-
+
60-
If the unsafe sysctls are not allowed for the node, the pod is scheduled,
61-
but does not deploy:
62-
+
60+
61+
. Verify that the pod is scheduled but does not deploy because unsafe sysctls are not allowed for the node using the following command:
62+
+
6363
[source,terminal]
6464
----
6565
$ oc get pod
@@ -68,6 +68,6 @@ $ oc get pod
6868
.Example output
6969
[source,terminal]
7070
----
71-
NAME READY STATUS RESTARTS AGE
72-
hello-pod 0/1 SysctlForbidden 0 14s
71+
NAME READY STATUS RESTARTS AGE
72+
sysctl-example-unsafe 0/1 SysctlForbidden 0 14s
7373
----

0 commit comments

Comments
 (0)