1
1
---
2
- title : 通过配置文件设置 Kubelet 参数
2
+ title : 通过配置文件设置 kubelet 参数
3
3
content_type : task
4
4
weight : 330
5
5
---
6
6
<!--
7
7
reviewers:
8
8
- mtaufen
9
9
- dawnchen
10
- title: Set Kubelet parameters via a config file
10
+ title: Set Kubelet Parameters Via A Configuration File
11
11
content_type: task
12
12
weight: 330
13
13
--->
14
14
15
15
<!-- overview -->
16
16
17
17
<!--
18
- A subset of the Kubelet 's configuration parameters may be
18
+ A subset of the kubelet 's configuration parameters may be
19
19
set via an on-disk config file, as a substitute for command-line flags.
20
20
--->
21
21
通过保存在硬盘的配置文件设置 kubelet 的部分配置参数,这可以作为命令行参数的替代。
@@ -31,26 +31,26 @@ it simplifies node deployment and configuration management.
31
31
<!--
32
32
## Create the config file
33
33
34
- The subset of the Kubelet 's configuration that can be configured via a file
34
+ The subset of the kubelet 's configuration that can be configured via a file
35
35
is defined by the
36
36
[`KubeletConfiguration`](/docs/reference/config-api/kubelet-config.v1beta1/)
37
37
struct.
38
38
-->
39
39
## 创建配置文件 {#create-config-file}
40
40
41
41
[ ` KubeletConfiguration ` ] ( /zh-cn/docs/reference/config-api/kubelet-config.v1beta1/ )
42
- 结构体定义了可以通过文件配置的 Kubelet 配置子集,
42
+ 结构体定义了可以通过文件配置的 kubelet 配置子集,
43
43
44
44
<!--
45
45
The configuration file must be a JSON or YAML representation of the parameters
46
- in this struct. Make sure the Kubelet has read permissions on the file.
46
+ in this struct. Make sure the kubelet has read permissions on the file.
47
47
48
48
Here is an example of what this file might look like:
49
49
-->
50
50
配置文件必须是这个结构体中参数的 JSON 或 YAML 表现形式。
51
51
确保 kubelet 可以读取该文件。
52
52
53
- 下面是一个 Kubelet 配置文件示例:
53
+ 下面是一个 kubelet 配置文件示例:
54
54
55
55
``` yaml
56
56
apiVersion : kubelet.config.k8s.io/v1beta1
@@ -63,13 +63,13 @@ evictionHard:
63
63
` ` `
64
64
65
65
<!--
66
- In the example, the Kubelet is configured to serve on IP address 192.168.0.8 and port 20250, pull images in parallel,
66
+ In the example, the kubelet is configured to serve on IP address 192.168.0.8 and port 20250, pull images in parallel,
67
67
and evict Pods when available memory drops below 200Mi. Since only one of the four evictionHard thresholds is configured,
68
68
other evictionHard thresholds are reset to 0 from their built-in defaults.
69
- All other Kubelet configuration values are left at their built-in defaults, unless overridden
69
+ All other kubelet configuration values are left at their built-in defaults, unless overridden
70
70
by flags. Command line flags which target the same value as a config file will override that value.
71
71
-->
72
- 在这个示例中, Kubelet 被设置为在地址 192.168.0.8 端口 20250 上提供服务,以并行方式拉取镜像,
72
+ 在这个示例中, kubelet 被设置为在地址 192.168.0.8 端口 20250 上提供服务,以并行方式拉取镜像,
73
73
当可用内存低于 200Mi 时, kubelet 将会开始驱逐 Pod。
74
74
由于仅配置了四个 evictionHard 阈值之一,因此其他 evictionHard 阈值被重置为 0,而不是使用其内置默认值。
75
75
没有声明的其余配置项都将使用默认值,除非使用命令行参数来重载。
@@ -87,9 +87,9 @@ the threshold values respectively.
87
87
{{< /note >}}
88
88
89
89
<!--
90
- ## Start a Kubelet process configured via the config file
90
+ ## Start a kubelet process configured via the config file
91
91
--->
92
- ## 启动通过配置文件配置的 Kubelet 进程 {#start-kubelet-via-config-file}
92
+ ## 启动通过配置文件配置的 kubelet 进程 {#start-kubelet-via-config-file}
93
93
94
94
{{< note >}}
95
95
<!--
@@ -101,10 +101,10 @@ See [configuring kubelet using kubeadm](/docs/setup/production-environment/tools
101
101
{{< /note >}}
102
102
103
103
<!--
104
- Start the Kubelet with the `--config` flag set to the path of the Kubelet 's config file.
105
- The Kubelet will then load its config from this file.
104
+ Start the kubelet with the `--config` flag set to the path of the kubelet 's config file.
105
+ The kubelet will then load its config from this file.
106
106
-->
107
- 启动 Kubelet 需要将 `--config` 参数设置为 Kubelet 配置文件的路径。Kubelet 将从此文件加载其配置。
107
+ 启动 kubelet 需要将 `--config` 参数设置为 kubelet 配置文件的路径。kubelet 将从此文件加载其配置。
108
108
109
109
<!--
110
110
Note that command line flags which target the same value as a config file will override that value.
@@ -114,23 +114,106 @@ This helps ensure backwards compatibility with the command-line API.
114
114
这有助于确保命令行 API 的向后兼容性。
115
115
116
116
<!--
117
- Note that relative file paths in the Kubelet config file are resolved relative to the
118
- location of the Kubelet config file, whereas relative paths in command line flags are resolved
119
- relative to the Kubelet 's current working directory.
117
+ Note that relative file paths in the kubelet config file are resolved relative to the
118
+ location of the kubelet config file, whereas relative paths in command line flags are resolved
119
+ relative to the kubelet 's current working directory.
120
120
-->
121
121
请注意,kubelet 配置文件中的相对文件路径是相对于 kubelet 配置文件的位置解析的,
122
122
而命令行参数中的相对路径是相对于 kubelet 的当前工作目录解析的。
123
123
124
124
<!--
125
- Note that some default values differ between command-line flags and the Kubelet config file.
125
+ Note that some default values differ between command-line flags and the kubelet config file.
126
126
If `--config` is provided and the values are not specified via the command line, the
127
127
defaults for the `KubeletConfiguration` version apply.
128
128
In the above example, this version is `kubelet.config.k8s.io/v1beta1`.
129
129
--->
130
- 请注意,命令行参数和 Kubelet 配置文件的某些默认值不同。
130
+ 请注意,命令行参数和 kubelet 配置文件的某些默认值不同。
131
131
如果设置了 `--config`,并且没有通过命令行指定值,则 `KubeletConfiguration`
132
132
版本的默认值生效。在上面的例子中,version 是 `kubelet.config.k8s.io/v1beta1`。
133
133
134
+ <!--
135
+ # # Drop-in directory for kubelet configuration files {#kubelet-conf-d}
136
+
137
+ 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
138
+ ` --config-dir` flag, and it defaults to `""`, or disabled, by default.
139
+ -->
140
+ # # kubelet 配置文件的插件目录 {#kubelet-conf-d}
141
+
142
+ 自 Kubernetes v1.28.0 起,kubelet 被扩展以支持一个插件配置目录。
143
+ 该目录的位置可以使用 `--config-dir` 标志来指定,默认为 `""`,也就是被禁用状态。
144
+
145
+ <!--
146
+ 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).
147
+ For Kubernetes v{{< skew currentVersion >}}, the kubelet returns an error if you specify `--config-dir` without that variable set, and startup fails.
148
+ You cannot specify the drop-in configuration directory using the kubelet configuration file; only the CLI argument `--config-dir` can set it.
149
+ -->
150
+ 只有在为 kubelet 进程设置环境变量 `KUBELET_CONFIG_DROPIN_DIR_ALPHA`
151
+ (该变量的值无关紧要)时才可以设置 `--config-dir`。对于 Kubernetes v{{< skew currentVersion >}},
152
+ 如果你未设置该变量而指定了 `--config-dir`,kubelet 将返回错误并且启动失败。
153
+ 你不能使用 kubelet 配置文件指定插件配置目录;只能使用 CLI 参数 `--config-dir` 进行设置。
154
+
155
+ <!--
156
+ One can use the kubelet configuration directory in a similar way to the kubelet config file.
157
+ -->
158
+ 你可以以类似于 kubelet 配置文件的方式使用 kubelet 配置目录。
159
+
160
+ {{< note >}}
161
+ <!--
162
+ The suffix of a valid kubelet drop-in configuration file must be `.conf`. For instance : ` 99-kubelet-address.conf`
163
+ -->
164
+ 合法的 kubelet 插件配置文件的后缀必须为 `.conf`。例如 `99-kubelet-address.conf`。
165
+ {{< /note >}}
166
+
167
+ <!--
168
+ 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 :
169
+
170
+ Main kubelet configuration file contents :
171
+ -->
172
+ 例如,你可能想要为所有节点设置一个基准的 kubelet 配置,但你可能想要自定义 `address` 字段。
173
+ 可以按如下方式操作:
174
+
175
+ kubelet 配置文件的主要内容如下:
176
+
177
+ ` ` ` yaml
178
+ apiVersion: kubelet.config.k8s.io/v1beta1
179
+ kind: KubeletConfiguration
180
+ port: 20250
181
+ serializeImagePulls: false
182
+ evictionHard:
183
+ memory.available: "200Mi"
184
+ ` ` `
185
+
186
+ <!--
187
+ Contents of a file in `--config-dir` directory :
188
+ -->
189
+ ` --config-dir` 目录中某个文件的内容如下:
190
+
191
+ ` ` ` yaml
192
+ apiVersion: kubelet.config.k8s.io/v1beta1
193
+ kind: KubeletConfiguration
194
+ address: "192.168.0.8"
195
+ ` ` `
196
+
197
+ <!--
198
+ On startup, the kubelet merges configuration from :
199
+
200
+ * Command line arguments (lowest precedence).
201
+ * the kubelet configuration
202
+ * Drop-in configuration files, according to sort order.
203
+ * Feature gates specified over the command line (highest precedence).
204
+ -->
205
+ 在启动时,kubelet 会合并来自以下几部分的配置:
206
+
207
+ * 命令行参数(优先级最低)。
208
+ * kubelet 配置文件。
209
+ * 排序的插件配置文件。
210
+ * 在命令行中指定的特性门控(优先级最高)。
211
+
212
+ <!--
213
+ This produces the same outcome as if you used the [single configuration file](#create-the-config-file) used in the earlier example.
214
+ -->
215
+ 这将产生与之前示例中使用的[单个配置文件](#create-the-config-file)相同的结果。
216
+
134
217
<!-- discussion -->
135
218
136
219
# # {{% heading "whatsnext" %}}
0 commit comments