@@ -12,6 +12,21 @@ content_type: task
1212weight: 330
1313--->
1414
15+ ## {{% heading "prerequisites" %}}
16+
17+ <!--
18+ Some steps in this page use the `jq` tool. If you don't have `jq`, you can
19+ install it via your operating system's software sources, or fetch it from
20+ [https://jqlang.github.io/jq/](https://jqlang.github.io/jq/).
21+
22+ Some steps also involve installing `curl`, which can be installed via your
23+ operating system's software sources.
24+ -->
25+ 此页面中的某些步骤使用 ` jq ` 工具。如果你没有 ` jq ` ,你可以通过操作系统的软件源安装它,或者从
26+ [ https://jqlang.github.io/jq/ ] ( https://jqlang.github.io/jq/ ) 中获取它。
27+
28+ 某些步骤还涉及安装 ` curl ` ,它可以通过操作系统的软件源安装。
29+
1530<!-- overview -->
1631
1732<!--
@@ -153,86 +168,260 @@ In the above example, this version is `kubelet.config.k8s.io/v1beta1`.
153168
154169<!--
155170# # Drop-in directory for kubelet configuration files {#kubelet-conf-d}
156-
157- As of Kubernetes v1.28.0, the Kubelet has been extended to support a drop-in configuration directory. The location of it can be specified with
158- ` --config-dir` flag, and it defaults to `""`, or disabled, by default.
159171-->
160172# # kubelet 配置文件的插件目录 {#kubelet-conf-d}
161173
162- 自 Kubernetes v1.28.0 起,kubelet 被扩展以支持一个插件配置目录。
163- 该目录的位置可以使用 `--config-dir` 标志来指定,默认为 `""`,也就是被禁用状态。
174+ {{<feature-state for_k8s_version="v1.30" state="beta" >}}
164175
165176<!--
166- You can only set `--config-dir` if you set the environment variable `KUBELET_CONFIG_DROPIN_DIR_ALPHA` for the kubelet process (the value of that variable does not matter).
167- For Kubernetes v{{< skew currentVersion >}}, the kubelet returns an error if you specify `--config-dir` without that variable set, and startup fails .
168- You cannot specify the drop-in configuration directory using the kubelet configuration file; only the CLI argument `--config-dir` can set it.
177+ You can specify a drop-in configuration directory for the kubelet. By default, the kubelet does not look
178+ for drop-in configuration files anywhere - you must specify a path .
179+ For example : ` --config-dir=/etc/kubernetes/kubelet.conf.d `
169180-->
170- 只有在为 kubelet 进程设置环境变量 `KUBELET_CONFIG_DROPIN_DIR_ALPHA`
171- (该变量的值无关紧要)时才可以设置 `--config-dir`。对于 Kubernetes v{{< skew currentVersion >}},
172- 如果你未设置该变量而指定了 `--config-dir`,kubelet 将返回错误并且启动失败。
173- 你不能使用 kubelet 配置文件指定插件配置目录;只能使用 CLI 参数 `--config-dir` 进行设置。
181+ 你可以为 kubelet 指定一个插件配置目录。默认情况下,kubelet
182+ 不会在任何地方查找插件配置文件 - 你必须指定路径。
183+ 例如:`--config-dir=/etc/kubernetes/kubelet.conf.d`
174184
175185<!--
176- One can use the kubelet configuration directory in a similar way to the kubelet config file.
186+ For Kubernetes v1.28 to v1.29, you can only specify `--config-dir` if you also set
187+ the environment variable `KUBELET_CONFIG_DROPIN_DIR_ALPHA` for the kubelet process (the value
188+ of that variable does not matter).
177189-->
178- 你可以以类似于 kubelet 配置文件的方式使用 kubelet 配置目录。
190+ 对于 Kubernetes v1.28 到 v1.29,如果你还为 kubelet
191+ 进程设置了环境变量 `KUBELET_CONFIG_DROPIN_DIR_ALPHA`(该变量的值无关紧要),
192+ 则只能指定 `--config-dir`。
179193
180194{{< note >}}
181195<!--
182- The suffix of a valid kubelet drop-in configuration file must be `.conf`. For instance : ` 99-kubelet-address.conf`
196+ The suffix of a valid kubelet drop-in configuration file ** must** be `.conf`. For instance : ` 99-kubelet-address.conf`
183197-->
184- 合法的 kubelet 插件配置文件的后缀必须为 `.conf`。例如 `99-kubelet-address.conf`。
198+ 合法的 kubelet 插件配置文件的后缀**必须**为 `.conf`。例如 `99-kubelet-address.conf`。
185199{{< /note >}}
186200
187201<!--
188- For instance, you may want a baseline kubelet configuration for all nodes, but you may want to customize the `address` field. This can be done as follows :
189-
190- Main kubelet configuration file contents :
202+ The kubelet processes files in its config drop-in directory by sorting the **entire file name** alphanumerically.
203+ For instance, `00-kubelet.conf` is processed first, and then overridden with a file named `01-kubelet.conf`.
191204-->
192- 例如,你可能想要为所有节点设置一个基准的 kubelet 配置,但你可能想要自定义 `address` 字段。
193- 可以按如下方式操作:
194-
195- kubelet 配置文件的主要内容如下:
205+ kubelet 通过按字母数字顺序对**整个文件名**进行排序来处理其配置插件目录中的文件。
206+ 例如,首先处理 `00-kubelet.conf`,然后用名为 `01-kubelet.conf` 的文件覆盖。
196207
197- ` ` ` yaml
198- apiVersion: kubelet.config.k8s.io/v1beta1
199- kind: KubeletConfiguration
200- port: 20250
201- serializeImagePulls: false
202- evictionHard:
203- memory.available: "200Mi"
204- ` ` `
208+ <!--
209+ These files may contain partial configurations and might not be valid config files by themselves.
210+ Validation is only performed on the final resulting configuration structure
211+ stored internally in the kubelet.
212+ This offers you flexibility in how you manage and combine kubelet configuration that comes from different sources.
213+ However, it's important to note that the behavior varies based on the data type of the configuration fields.
214+ -->
215+ 这些文件可能包含部分配置,并且它们本身可能不是有效的配置文件。
216+ 仅对 kubelet 内部存储的、最终生成的配置结构执行验证。
217+ 这让你能够灵活管理和组合不同来源的 kubelet 配置。
218+ 但是,请务必注意,产生的行为会根据配置字段的数据类型而有所不同。
205219
206220<!--
207- Contents of a file in `--config-dir` directory :
221+ Different data types in the kubelet configuration structure merge differently.
222+ See the [reference
223+ document](/docs/reference/node/kubelet-config-directory-merging.md) for more
224+ information.
208225-->
209- ` --config-dir` 目录中某个文件的内容如下:
226+ kubelet 配置结构中不同数据类型的合并方式不同。
227+ 有关详细信息,请参阅[参考文档](/zh-cn/docs/reference/node/kubelet-config-directory-merging.md)。
210228
211- ` ` ` yaml
212- apiVersion: kubelet.config.k8s.io/v1beta1
213- kind: KubeletConfiguration
214- address: "192.168.0.8"
215- ` ` `
229+ <!--
230+ # ## Kubelet configuration merging order
231+ -->
232+ # ## kubelet 配置合并顺序 {#kubelet-configuration-merging-order}
216233
217234<!--
218235On startup, the kubelet merges configuration from :
219236
220- * Command line arguments (lowest precedence).
221- * the kubelet configuration
237+ * Feature gates specified over the command line (lowest precedence).
238+ * The kubelet configuration.
222239* Drop-in configuration files, according to sort order.
223- * Feature gates specified over the command line (highest precedence).
240+ * Command line arguments excluding feature gates (highest precedence).
224241-->
225242在启动时,kubelet 会合并来自以下几部分的配置:
226243
227- * 命令行参数 (优先级最低)。
244+ * 在命令行中指定的特性门控 (优先级最低)。
228245* kubelet 配置文件。
229246* 排序的插件配置文件。
230- * 在命令行中指定的特性门控 (优先级最高)。
247+ * 不包括特性门控的命令行参数 (优先级最高)。
231248
249+ {{< note >}}
232250<!--
233- This produces the same outcome as if you used the [single configuration file](#create-the-config-file) used in the earlier example.
251+ The config drop-in dir mechanism for the kubelet is similar but different from how the `kubeadm` tool allows you to patch configuration.
252+ The `kubeadm` tool uses a specific [patching strategy](/docs/setup/production-environment/tools/kubeadm/control-plane-flags/#patches) for its configuration,
253+ whereas the only patch strategy for kubelet configuration drop-in files is `replace`. The kubelet determines the order of merges based on sorting the **suffixes** alphanumerically,
254+ and replaces every field present in a higher priority file.
234255-->
235- 这将产生与之前示例中使用的[单个配置文件](#create-the-config-file)相同的结果。
256+ kubelet 的配置插件目录机制类似,但与 `kubeadm` 工具允许 patch 配置的方式不同。
257+ ` kubeadm` 工具使用特定的[补丁策略](/zh-cn/docs/setup/production-environment/tools/kubeadm/control-plane-flags/#patches),
258+ 而 kubelet 配置插件文件的唯一补丁策略是 `replace`。kubelet 根据字母数字对**后缀**进行排序来确定合并顺序,
259+ 并替换更高优先级文件中存在的每个字段。
260+ {{< /note >}}
261+
262+ <!--
263+ # # Viewing the kubelet configuration
264+ -->
265+ # # 查看 kubelet 配置
266+
267+ <!--
268+ Since the configuration could now be spread over multiple files with this feature, if someone wants to inspect the final actuated configuration,
269+ they can follow these steps to inspect the kubelet configuration :
270+ -->
271+ 由于现在可以使用此特性将配置分布在多个文件中,因此如果有人想要检查最终启动的配置,
272+ 他们可以按照以下步骤检查 kubelet 配置:
273+
274+ <!--
275+ 1. Start a proxy server using [`kubectl proxy`](/docs/reference/kubectl/generated/kubectl-commands#proxy) in your terminal.
276+ -->
277+ 1. 在终端中使用 [`kubectl proxy`](/docs/reference/kubectl/generated/kubectl-commands#proxy) 启动代理服务器。
278+
279+ ` ` ` bash
280+ kubectl proxy
281+ ` ` `
282+
283+ <!--
284+ Which gives output like :
285+ -->
286+ 其输出如下:
287+
288+ ` ` ` bash
289+ Starting to serve on 127.0.0.1:8001
290+
291+ ` ` `
292+
293+ <!--
294+ 2. Open another terminal window and use `curl` to fetch the kubelet configuration.
295+ Replace `<node-name>` with the actual name of your node :
296+ -->
297+ 2. 打开另一个终端窗口并使用 `curl` 来获取 kubelet 配置。
298+ 将 `<node-name>` 替换为节点的实际名称:
299+
300+ ` ` ` bash
301+ curl -X GET http://127.0.0.1:8001/api/v1/nodes/<node-name>/proxy/configz | jq .
302+ ` ` `
303+
304+ ` ` ` bash
305+ {
306+ "kubeletconfig": {
307+ "enableServer": true,
308+ "staticPodPath": "/var/run/kubernetes/static-pods",
309+ "syncFrequency": "1m0s",
310+ "fileCheckFrequency": "20s",
311+ "httpCheckFrequency": "20s",
312+ "address": "192.168.1.16",
313+ "port": 10250,
314+ "readOnlyPort": 10255,
315+ "tlsCertFile": "/var/lib/kubelet/pki/kubelet.crt",
316+ "tlsPrivateKeyFile": "/var/lib/kubelet/pki/kubelet.key",
317+ "rotateCertificates": true,
318+ "authentication": {
319+ "x509": {
320+ "clientCAFile": "/var/run/kubernetes/client-ca.crt"
321+ },
322+ "webhook": {
323+ "enabled": true,
324+ "cacheTTL": "2m0s"
325+ },
326+ "anonymous": {
327+ "enabled": true
328+ }
329+ },
330+ "authorization": {
331+ "mode": "AlwaysAllow",
332+ "webhook": {
333+ "cacheAuthorizedTTL": "5m0s",
334+ "cacheUnauthorizedTTL": "30s"
335+ }
336+ },
337+ "registryPullQPS": 5,
338+ "registryBurst": 10,
339+ "eventRecordQPS": 50,
340+ "eventBurst": 100,
341+ "enableDebuggingHandlers": true,
342+ "healthzPort": 10248,
343+ "healthzBindAddress": "127.0.0.1",
344+ "oomScoreAdj": -999,
345+ "clusterDomain": "cluster.local",
346+ "clusterDNS": [
347+ "10.0.0.10"
348+ ],
349+ "streamingConnectionIdleTimeout": "4h0m0s",
350+ "nodeStatusUpdateFrequency": "10s",
351+ "nodeStatusReportFrequency": "5m0s",
352+ "nodeLeaseDurationSeconds": 40,
353+ "imageMinimumGCAge": "2m0s",
354+ "imageMaximumGCAge": "0s",
355+ "imageGCHighThresholdPercent": 85,
356+ "imageGCLowThresholdPercent": 80,
357+ "volumeStatsAggPeriod": "1m0s",
358+ "cgroupsPerQOS": true,
359+ "cgroupDriver": "systemd",
360+ "cpuManagerPolicy": "none",
361+ "cpuManagerReconcilePeriod": "10s",
362+ "memoryManagerPolicy": "None",
363+ "topologyManagerPolicy": "none",
364+ "topologyManagerScope": "container",
365+ "runtimeRequestTimeout": "2m0s",
366+ "hairpinMode": "promiscuous-bridge",
367+ "maxPods": 110,
368+ "podPidsLimit": -1,
369+ "resolvConf": "/run/systemd/resolve/resolv.conf",
370+ "cpuCFSQuota": true,
371+ "cpuCFSQuotaPeriod": "100ms",
372+ "nodeStatusMaxImages": 50,
373+ "maxOpenFiles": 1000000,
374+ "contentType": "application/vnd.kubernetes.protobuf",
375+ "kubeAPIQPS": 50,
376+ "kubeAPIBurst": 100,
377+ "serializeImagePulls": true,
378+ "evictionHard": {
379+ "imagefs.available": "15%",
380+ "memory.available": "100Mi",
381+ "nodefs.available": "10%",
382+ "nodefs.inodesFree": "5%"
383+ },
384+ "evictionPressureTransitionPeriod": "1m0s",
385+ "enableControllerAttachDetach": true,
386+ "makeIPTablesUtilChains": true,
387+ "iptablesMasqueradeBit": 14,
388+ "iptablesDropBit": 15,
389+ "featureGates": {
390+ "AllAlpha": false
391+ },
392+ "failSwapOn": false,
393+ "memorySwap": {},
394+ "containerLogMaxSize": "10Mi",
395+ "containerLogMaxFiles": 5,
396+ "configMapAndSecretChangeDetectionStrategy": "Watch",
397+ "enforceNodeAllocatable": [
398+ "pods"
399+ ],
400+ "volumePluginDir": "/usr/libexec/kubernetes/kubelet-plugins/volume/exec/",
401+ "logging": {
402+ "format": "text",
403+ "flushFrequency": "5s",
404+ "verbosity": 3,
405+ "options": {
406+ "json": {
407+ "infoBufferSize": "0"
408+ }
409+ }
410+ },
411+ "enableSystemLogHandler": true,
412+ "enableSystemLogQuery": false,
413+ "shutdownGracePeriod": "0s",
414+ "shutdownGracePeriodCriticalPods": "0s",
415+ "enableProfilingHandler": true,
416+ "enableDebugFlagsHandler": true,
417+ "seccompDefault": false,
418+ "memoryThrottlingFactor": 0.9,
419+ "registerNode": true,
420+ "localStorageCapacityIsolation": true,
421+ "containerRuntimeEndpoint": "unix:///var/run/crio/crio.sock"
422+ }
423+ }
424+ ` ` `
236425
237426<!-- discussion -->
238427
@@ -242,6 +431,9 @@ This produces the same outcome as if you used the [single configuration file](#c
242431- Learn more about kubelet configuration by checking the
243432 [`KubeletConfiguration`](/docs/reference/config-api/kubelet-config.v1beta1/)
244433 reference.
434+ - Learn more about kubelet configuration merging in the
435+ [reference document](/docs/reference/node/kubelet-config-directory-merging.md).
245436--->
246437- 参阅 [`KubeletConfiguration`](/zh-cn/docs/reference/config-api/kubelet-config.v1beta1/)
247438 进一步学习 kubelet 的配置。
439+ - 在[参考文档](/zh-cn/docs/reference/node/kubelet-config-directory-merging.md)中了解有关 kubelet 配置合并的更多信息。
0 commit comments