@@ -18,30 +18,30 @@ This document describes how to configure and use kernel parameters within a
18
18
Kubernetes cluster using the {{< glossary_tooltip term_id="sysctl" >}}
19
19
interface.
20
20
-->
21
+
21
22
本文档介绍如何通过 {{< glossary_tooltip term_id="sysctl" >}}
22
23
接口在 Kubernetes 集群中配置和使用内核参数。
23
24
24
25
<!--
25
26
Starting from Kubernetes version 1.23, the kubelet supports the use of either `/` or `.`
26
27
as separators for sysctl names.
28
+ Starting from Kubernetes version 1.25, setting Sysctls for a Pod supports setting sysctls with slashes.
27
29
For example, you can represent the same sysctl name as `kernel.shm_rmid_forced` using a
28
30
period as the separator, or as `kernel/shm_rmid_forced` using a slash as a separator.
29
31
For more sysctl parameter conversion method details, please refer to
30
32
the page [sysctl.d(5)](https://man7.org/linux/man-pages/man5/sysctl.d.5.html) from
31
33
the Linux man-pages project.
32
- Setting Sysctls for a Pod and PodSecurityPolicy features do not yet support
33
- setting sysctls with slashes.
34
34
-->
35
35
{{< note >}}
36
36
从 Kubernetes 1.23 版本开始,kubelet 支持使用 ` / ` 或 ` . ` 作为 sysctl 参数的分隔符。
37
+ 从 Kubernetes 1.25 版本开始,支持为 Pod 设置 sysctl 时使用设置名字带有斜线的 sysctl。
37
38
例如,你可以使用点或者斜线作为分隔符表示相同的 sysctl 参数,以点作为分隔符表示为: ` kernel.shm_rmid_forced ` ,
38
39
或者以斜线作为分隔符表示为:` kernel/shm_rmid_forced ` 。
39
40
更多 sysctl 参数转换方法详情请参考 Linux man-pages
40
- [ sysctl.d(5)] ( https://man7.org/linux/man-pages/man5/sysctl.d.5.html ) 。
41
- 设置 Pod 的 Sysctl 参数 和 PodSecurityPolicy 功能尚不支持设置包含斜线的 Sysctl 参数。
41
+ [ sysctl.d(5)] ( https://man7.org/linux/man-pages/man5/sysctl.d.5.html ) 。
42
42
{{< /note >}}
43
- ## {{% heading "prerequisites" %}}
44
43
44
+ ## {{% heading "prerequisites" %}}
45
45
46
46
{{< include "task-tutorial-prereqs.md" >}}
47
47
@@ -82,7 +82,7 @@ process file system. The parameters cover various subsystems such as:
82
82
<!--
83
83
To get a list of all parameters, you can run
84
84
--->
85
- 若要获取完整的参数列表,请执行以下命令
85
+ 若要获取完整的参数列表,请执行以下命令:
86
86
87
87
``` shell
88
88
sudo sysctl -a
@@ -95,7 +95,7 @@ Sysctls are grouped into _safe_ and _unsafe_ sysctls. In addition to proper
95
95
namespacing a _safe_ sysctl must be properly _isolated_ between pods on the same
96
96
node. This means that setting a _safe_ sysctl for one pod
97
97
-->
98
- ## 启用非安全的 Sysctl 参数
98
+ ## 启用非安全的 Sysctl 参数 {#enabling-usafe-sysctls}
99
99
100
100
sysctl 参数分为 ** 安全** 和 ** 非安全的** 。
101
101
** 安全** 的 sysctl 参数除了需要设置恰当的命名空间外,在同一节点上的不同 Pod
@@ -121,8 +121,8 @@ The following sysctls are supported in the _safe_ set:
121
121
- ` kernel.shm_rmid_forced `
122
122
- ` net.ipv4.ip_local_port_range `
123
123
- ` net.ipv4.tcp_syncookies `
124
- - ` net.ipv4.ping_group_range ` (从 Kubernetes 1.18 开始)
125
- - ` net.ipv4.ip_unprivileged_port_start ` (从 Kubernetes 1.22 开始)。
124
+ - ` net.ipv4.ping_group_range ` (从 Kubernetes 1.18 开始)
125
+ - ` net.ipv4.ip_unprivileged_port_start ` (从 Kubernetes 1.22 开始)。
126
126
127
127
<!--
128
128
The example `net.ipv4.tcp_syncookies` is not namespaced on Linux kernel version 4.4 or lower.
@@ -135,8 +135,8 @@ The example `net.ipv4.tcp_syncookies` is not namespaced on Linux kernel version
135
135
This list will be extended in future Kubernetes versions when the kubelet
136
136
supports better isolation mechanisms.
137
137
-->
138
- 在未来的 Kubernetes 版本中,若 kubelet 支持更好的隔离机制,则上述列表中将会
139
- 列出更多 ** 安全的** sysctl 参数。
138
+ 在未来的 Kubernetes 版本中,若 kubelet 支持更好的隔离机制,
139
+ 则上述列表中将会列出更多 ** 安全的** sysctl 参数。
140
140
141
141
<!--
142
142
All _safe_ sysctls are enabled by default.
@@ -188,7 +188,7 @@ are configurable via the pod securityContext within Kubernetes.
188
188
-->
189
189
## 设置 Pod 的 Sysctl 参数
190
190
191
- 目前,在 Linux 内核中,有许多的 sysctl 参数都是 _ 有命名空间的 _ 。
191
+ 目前,在 Linux 内核中,有许多的 sysctl 参数都是 ** 有命名空间的 ** 。
192
192
这就意味着可以为节点上的每个 Pod 分别去设置它们的 sysctl 参数。
193
193
在 Kubernetes 中,只有那些有命名空间的 sysctl 参数可以通过 Pod 的 securityContext 对其进行配置。
194
194
@@ -258,17 +258,16 @@ spec:
258
258
...
259
259
```
260
260
261
-
262
261
<!-- discussion -->
262
+
263
263
<!--
264
264
Due to their nature of being _unsafe_, the use of _unsafe_ sysctls
265
265
is at-your-own-risk and can lead to severe problems like wrong behavior of
266
266
containers, resource shortage or complete breakage of a node.
267
267
-->
268
268
{{< warning >}}
269
- 由于 ** 非安全的** sysctl 参数其本身具有不稳定性,在使用 ** 非安全的** sysctl 参数
270
- 时可能会导致一些严重问题,如容器的错误行为、机器资源不足或节点被完全破坏,
271
- 用户需自行承担风险。
269
+ 由于 ** 非安全的** sysctl 参数其本身具有不稳定性,在使用 ** 非安全的** sysctl 参数时可能会导致一些严重问题,
270
+ 如容器的错误行为、机器资源不足或节点被完全破坏,用户需自行承担风险。
272
271
{{< /warning >}}
273
272
274
273
<!--
@@ -277,10 +276,9 @@ _tainted_ within a cluster, and only schedule pods onto them which need those
277
276
sysctl settings. It is suggested to use the Kubernetes [_taints and toleration_
278
277
feature](/docs/reference/generated/kubectl/kubectl-commands/#taint) to implement this.
279
278
-->
280
- 最佳实践方案是将集群中具有特殊 sysctl 设置的节点视为 ** 有污点的** ,并且只调度
281
- 需要使用到特殊 sysctl 设置的 Pod 到这些节点上。
282
- 建议使用 Kubernetes 的
283
- [ 污点和容忍度特性] ( /docs/reference/generated/kubectl/kubectl-commands/#taint ) 来实现它。
279
+ 最佳实践方案是将集群中具有特殊 sysctl 设置的节点视为 ** 有污点的** ,并且只调度需要使用到特殊
280
+ sysctl 设置的 Pod 到这些节点上。建议使用 Kubernetes
281
+ 的[ 污点和容忍度特性] ( /docs/reference/generated/kubectl/kubectl-commands/#taint ) 来实现它。
284
282
285
283
<!--
286
284
A pod with the _unsafe_ sysctls will fail to launch on any node which has not
@@ -290,99 +288,11 @@ is recommended to use
290
288
[taints on nodes](/docs/concepts/scheduling-eviction/taint-and-toleration/)
291
289
to schedule those pods onto the right nodes.
292
290
-->
293
- 设置了 ** 非安全的** sysctl 参数的 Pod 在禁用了这两种 ** 非安全的** sysctl 参数配置
294
- 的节点上启动都会失败。与 ** 节点级别的** sysctl 一样,建议开启
295
- [ 污点和容忍度特性] ( /docs/reference/generated/kubectl/kubectl-commands/#taint ) 或
296
- [ 为节点配置污点] ( /zh-cn/docs/concepts/scheduling-eviction/taint-and-toleration/ )
297
- 以便将 Pod 调度到正确的节点之上。
298
-
299
- ## PodSecurityPolicy
300
-
301
- {{< feature-state for_k8s_version="v1.21" state="deprecated" >}}
302
-
303
- <!--
304
- You can further control which sysctls can be set in pods by specifying lists of
305
- sysctls or sysctl patterns in the `forbiddenSysctls` and/or
306
- `allowedUnsafeSysctls` fields of the PodSecurityPolicy. A sysctl pattern ends
307
- with a `*` character, such as `kernel.*`. A `*` character on its own matches
308
- all sysctls.
309
- -->
310
- 你可以通过在 PodSecurityPolicy 的 ` forbiddenSysctls ` 和/或 ` allowedUnsafeSysctls `
311
- 字段中,指定 sysctl 或填写 sysctl 匹配模式来进一步为 Pod 设置 sysctl 参数。
312
- sysctl 参数匹配模式以 ` * ` 字符结尾,如 ` kernel.* ` 。
313
- 单独的 ` * ` 字符匹配所有 sysctl 参数。
291
+ 设置了 ** 非安全的** sysctl 参数的 Pod 在禁用了这两种 ** 非安全的** sysctl 参数配置的节点上启动都会失败。
292
+ 与 ** 节点级别的** sysctl 一样,
293
+ 建议开启[ 污点和容忍度特性] ( /docs/reference/generated/kubectl/kubectl-commands/#taint ) 或
294
+ [ 为节点配置污点] ( /zh-cn/docs/concepts/scheduling-eviction/taint-and-toleration/ ) 以便将
295
+ Pod 调度到正确的节点之上。
314
296
315
- <!--
316
- By default, all safe sysctls are allowed.
317
- -->
318
- 所有 ** 安全的** sysctl 参数都默认启用。
319
-
320
- <!--
321
- Both `forbiddenSysctls` and `allowedUnsafeSysctls` are lists of plain sysctl names
322
- or sysctl patterns (which end with `*`). The string `*` matches all sysctls.
323
- -->
324
- ` forbiddenSysctls ` 和 ` allowedUnsafeSysctls ` 的值都是字符串列表类型,
325
- 可以添加 sysctl 参数名称,也可以添加 sysctl 参数匹配模式(以` * ` 结尾)。
326
- 只填写 ` * ` 则匹配所有的 sysctl 参数。
327
-
328
- <!--
329
- The `forbiddenSysctls` field excludes specific sysctls. You can forbid a
330
- combination of safe and unsafe sysctls in the list. To forbid setting any
331
- sysctls, use `*` on its own.
332
- -->
333
- ` forbiddenSysctls ` 字段用于禁用特定的 sysctl 参数。
334
- 你可以在列表中禁用安全和非安全的 sysctl 参数的组合。
335
- 要禁用所有的 sysctl 参数,请设置为 ` * ` 。
336
297
337
- <!--
338
- If you specify any unsafe sysctl in the `allowedUnsafeSysctls` field and it is
339
- not present in the `forbiddenSysctls` field, that sysctl can be used in Pods
340
- using this PodSecurityPolicy. To allow all unsafe sysctls in the
341
- PodSecurityPolicy to be set, use `*` on its own.
342
- -->
343
- 如果要在 ` allowedUnsafeSysctls ` 字段中指定一个非安全的 sysctl 参数,
344
- 并且它在 ` forbiddenSysctls ` 字段中未被禁用,则可以在 Pod 中通过
345
- PodSecurityPolicy 启用该 sysctl 参数。
346
- 若要在 PodSecurityPolicy 中开启所有非安全的 sysctl 参数,
347
- 请设 ` allowedUnsafeSysctls ` 字段值为 ` * ` 。
348
-
349
- <!--
350
- Do not configure these two fields such that there is overlap, meaning that a
351
- given sysctl is both allowed and forbidden.
352
- -->
353
- ` allowedUnsafeSysctls ` 与 ` forbiddenSysctls ` 两字段的配置不能重叠,
354
- 否则这就意味着存在某个 sysctl 参数既被启用又被禁用。
355
-
356
- <!--
357
- If you whitelist unsafe sysctls via the `allowedUnsafeSysctls` field
358
- in a PodSecurityPolicy, any pod using such a sysctl will fail to start
359
- if the sysctl is not whitelisted via the `--allowed-unsafe-sysctls` kubelet
360
- flag as well on that node.
361
- --->
362
- {{< warning >}}
363
- 如果你通过 PodSecurityPolicy 中的 ` allowedUnsafeSysctls ` 字段将非安全的 sysctl
364
- 参数列入白名单,但该 sysctl 参数未通过 kubelet 命令行参数
365
- ` --allowed-unsafe-sysctls ` 在节点上将其列入白名单,则设置了这个 sysctl
366
- 参数的 Pod 将会启动失败。
367
- {{< /warning >}}
368
-
369
- <!--
370
- This example allows unsafe sysctls prefixed with `kernel.msg` to be set and
371
- disallows setting of the `kernel.shm_rmid_forced` sysctl.
372
- -->
373
- 以下示例设置启用了以 ` kernel.msg ` 为前缀的非安全的 sysctl 参数,同时禁用了
374
- sysctl 参数 ` kernel.shm_rmid_forced ` 。
375
-
376
- ``` yaml
377
- apiVersion : policy/v1beta1
378
- kind : PodSecurityPolicy
379
- metadata :
380
- name : sysctl-psp
381
- spec :
382
- allowedUnsafeSysctls :
383
- - kernel.msg*
384
- forbiddenSysctls :
385
- - kernel.shm_rmid_forced
386
- ...
387
- ```
388
298
0 commit comments