Skip to content

Commit d709a81

Browse files
authored
Merge pull request #36368 from windsonsea/troerr
[zh] Sync1.25 /administer-cluster/sysctl-cluster.md
2 parents bbb7c59 + d616ba2 commit d709a81

File tree

1 file changed

+23
-113
lines changed

1 file changed

+23
-113
lines changed

content/zh-cn/docs/tasks/administer-cluster/sysctl-cluster.md

Lines changed: 23 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -18,30 +18,30 @@ This document describes how to configure and use kernel parameters within a
1818
Kubernetes cluster using the {{< glossary_tooltip term_id="sysctl" >}}
1919
interface.
2020
-->
21+
2122
本文档介绍如何通过 {{< glossary_tooltip term_id="sysctl" >}}
2223
接口在 Kubernetes 集群中配置和使用内核参数。
2324

2425
<!--
2526
Starting from Kubernetes version 1.23, the kubelet supports the use of either `/` or `.`
2627
as separators for sysctl names.
28+
Starting from Kubernetes version 1.25, setting Sysctls for a Pod supports setting sysctls with slashes.
2729
For example, you can represent the same sysctl name as `kernel.shm_rmid_forced` using a
2830
period as the separator, or as `kernel/shm_rmid_forced` using a slash as a separator.
2931
For more sysctl parameter conversion method details, please refer to
3032
the page [sysctl.d(5)](https://man7.org/linux/man-pages/man5/sysctl.d.5.html) from
3133
the Linux man-pages project.
32-
Setting Sysctls for a Pod and PodSecurityPolicy features do not yet support
33-
setting sysctls with slashes.
3434
-->
3535
{{< note >}}
3636
从 Kubernetes 1.23 版本开始,kubelet 支持使用 `/``.` 作为 sysctl 参数的分隔符。
37+
从 Kubernetes 1.25 版本开始,支持为 Pod 设置 sysctl 时使用设置名字带有斜线的 sysctl。
3738
例如,你可以使用点或者斜线作为分隔符表示相同的 sysctl 参数,以点作为分隔符表示为: `kernel.shm_rmid_forced`
3839
或者以斜线作为分隔符表示为:`kernel/shm_rmid_forced`
3940
更多 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)
4242
{{< /note >}}
43-
## {{% heading "prerequisites" %}}
4443

44+
## {{% heading "prerequisites" %}}
4545

4646
{{< include "task-tutorial-prereqs.md" >}}
4747

@@ -82,7 +82,7 @@ process file system. The parameters cover various subsystems such as:
8282
<!--
8383
To get a list of all parameters, you can run
8484
--->
85-
若要获取完整的参数列表,请执行以下命令
85+
若要获取完整的参数列表,请执行以下命令
8686

8787
```shell
8888
sudo sysctl -a
@@ -95,7 +95,7 @@ Sysctls are grouped into _safe_ and _unsafe_ sysctls. In addition to proper
9595
namespacing a _safe_ sysctl must be properly _isolated_ between pods on the same
9696
node. This means that setting a _safe_ sysctl for one pod
9797
-->
98-
## 启用非安全的 Sysctl 参数
98+
## 启用非安全的 Sysctl 参数 {#enabling-usafe-sysctls}
9999

100100
sysctl 参数分为 **安全****非安全的**
101101
**安全** 的 sysctl 参数除了需要设置恰当的命名空间外,在同一节点上的不同 Pod
@@ -121,8 +121,8 @@ The following sysctls are supported in the _safe_ set:
121121
- `kernel.shm_rmid_forced`
122122
- `net.ipv4.ip_local_port_range`
123123
- `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 开始)。
126126

127127
<!--
128128
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
135135
This list will be extended in future Kubernetes versions when the kubelet
136136
supports better isolation mechanisms.
137137
-->
138-
在未来的 Kubernetes 版本中,若 kubelet 支持更好的隔离机制,则上述列表中将会
139-
列出更多 **安全的** sysctl 参数。
138+
在未来的 Kubernetes 版本中,若 kubelet 支持更好的隔离机制,
139+
则上述列表中将会列出更多 **安全的** sysctl 参数。
140140

141141
<!--
142142
All _safe_ sysctls are enabled by default.
@@ -188,7 +188,7 @@ are configurable via the pod securityContext within Kubernetes.
188188
-->
189189
## 设置 Pod 的 Sysctl 参数
190190

191-
目前,在 Linux 内核中,有许多的 sysctl 参数都是 _有命名空间的_
191+
目前,在 Linux 内核中,有许多的 sysctl 参数都是 **有命名空间的**
192192
这就意味着可以为节点上的每个 Pod 分别去设置它们的 sysctl 参数。
193193
在 Kubernetes 中,只有那些有命名空间的 sysctl 参数可以通过 Pod 的 securityContext 对其进行配置。
194194

@@ -258,17 +258,16 @@ spec:
258258
...
259259
```
260260

261-
262261
<!-- discussion -->
262+
263263
<!--
264264
Due to their nature of being _unsafe_, the use of _unsafe_ sysctls
265265
is at-your-own-risk and can lead to severe problems like wrong behavior of
266266
containers, resource shortage or complete breakage of a node.
267267
-->
268268
{{< warning >}}
269-
由于 **非安全的** sysctl 参数其本身具有不稳定性,在使用 **非安全的** sysctl 参数
270-
时可能会导致一些严重问题,如容器的错误行为、机器资源不足或节点被完全破坏,
271-
用户需自行承担风险。
269+
由于 **非安全的** sysctl 参数其本身具有不稳定性,在使用 **非安全的** sysctl 参数时可能会导致一些严重问题,
270+
如容器的错误行为、机器资源不足或节点被完全破坏,用户需自行承担风险。
272271
{{< /warning >}}
273272

274273
<!--
@@ -277,10 +276,9 @@ _tainted_ within a cluster, and only schedule pods onto them which need those
277276
sysctl settings. It is suggested to use the Kubernetes [_taints and toleration_
278277
feature](/docs/reference/generated/kubectl/kubectl-commands/#taint) to implement this.
279278
-->
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) 来实现它。
284282

285283
<!--
286284
A pod with the _unsafe_ sysctls will fail to launch on any node which has not
@@ -290,99 +288,11 @@ is recommended to use
290288
[taints on nodes](/docs/concepts/scheduling-eviction/taint-and-toleration/)
291289
to schedule those pods onto the right nodes.
292290
-->
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 调度到正确的节点之上。
314296

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 参数,请设置为 `*`
336297

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-
```
388298

0 commit comments

Comments
 (0)