@@ -48,17 +48,79 @@ This guide demonstrates how to configure the kubelet's image credential provider
48
48
49
49
本指南演示如何配置 kubelet 的镜像凭据提供程序插件机制。
50
50
51
+ <!--
52
+ ## Service Account Token for Image Pulls
53
+ -->
54
+ ## 使用服务帐号令牌拉取镜像 {#service-account-token-for-image-pulls}
55
+
56
+ {{< feature-state feature_gate_name="KubeletServiceAccountTokenForCredentialProviders" >}}
57
+
58
+ <!--
59
+ Starting from Kubernetes v1.33,
60
+ the kubelet can be configured to send a service account token
61
+ bound to the pod for which the image pull is being performed
62
+ to the credential provider plugin.
63
+
64
+ This allows the plugin to exchange the token for credentials
65
+ to access the image registry.
66
+ -->
67
+ 从 Kubernetes v1.33 开始,
68
+ 可以配置 kubelet 在为 Pod 执行镜像拉取时发送一个与该 Pod
69
+ 绑定的服务账号令牌给凭据提供者插件。
70
+
71
+ 这允许插件用该令牌交换访问镜像仓库的凭据。
72
+
73
+ <!--
74
+ To enable this feature,
75
+ the `KubeletServiceAccountTokenForCredentialProviders` feature gate
76
+ must be enabled on the kubelet,
77
+ and the `tokenAttributes` field must be set
78
+ in the `CredentialProviderConfig` file for the plugin.
79
+
80
+ The `tokenAttributes` field contains information
81
+ about the service account token that will be passed to the plugin,
82
+ including the intended audience for the token
83
+ and whether the plugin requires the pod to have a service account.
84
+ -->
85
+ 要启用此特性,
86
+ 必须在 kubelet 上启用 ` KubeletServiceAccountTokenForCredentialProviders ` 特性门控,
87
+ 并且必须在插件的 ` CredentialProviderConfig ` 文件中设置 ` tokenAttributes ` 字段。
88
+
89
+ ` tokenAttributes ` 字段包含将传递给插件的服务帐号令牌的信息,
90
+ 包括令牌的预期受众和插件是否要求 Pod 拥有服务帐号。
91
+
92
+ <!--
93
+ Using service account token credentials can enable the following use-cases:
94
+
95
+ * Avoid needing a kubelet/node-based identity to pull images from a registry.
96
+ * Allow workloads to pull images based on their own runtime identity
97
+ without long-lived/persisted secrets.
98
+ -->
99
+ 使用服务帐号令牌凭据可以启用以下用例:
100
+
101
+ * 避免需要基于 kubelet/节点的身份从镜像仓库拉取镜像。
102
+ * 允许工作负载根据其自身的运行时身份拉取镜像,
103
+ 而无需长期存在的/持久化的 Secret。
104
+
51
105
## {{% heading "prerequisites" %}}
52
106
53
107
<!--
54
108
* You need a Kubernetes cluster with nodes that support kubelet credential
55
109
provider plugins. This support is available in Kubernetes {{< skew currentVersion >}};
56
110
Kubernetes v1.24 and v1.25 included this as a beta feature, enabled by default.
111
+ * If you are configuring a credential provider plugin
112
+ that requires the service account token,
113
+ you need a Kubernetes cluster with nodes running Kubernetes v1.33 or later
114
+ and the `KubeletServiceAccountTokenForCredentialProviders` feature gate
115
+ enabled on the kubelet.
57
116
* A working implementation of a credential provider exec plugin. You can build your own plugin or use one provided by cloud providers.
58
117
-->
59
118
* 你需要一个 Kubernetes 集群,其节点支持 kubelet 凭据提供程序插件。
60
119
这种支持在 Kubernetes {{< skew currentVersion >}} 中可用;
61
120
Kubernetes v1.24 和 v1.25 将此作为 Beta 特性包含在内,默认启用。
121
+ * 如果你正在配置需要服务帐号令牌的凭据提供者插件,
122
+ 你需要一个运行 Kubernetes v1.33 或更高版本的 Kubernetes 集群,
123
+ 并且在 kubelet 上启用了 ` KubeletServiceAccountTokenForCredentialProviders ` 特性门控。
62
124
* 凭据提供程序 exec 插件的一种可用的实现。你可以构建自己的插件或使用云提供商提供的插件。
63
125
64
126
{{< version-check >}}
@@ -106,6 +168,112 @@ kubelet 会读取通过 `--image-credential-provider-config` 设定的配置文
106
168
如果你正在使用基于 [ ECR-based 插件] ( https://github.com/kubernetes/cloud-provider-aws/tree/master/cmd/ecr-credential-provider ) ,
107
169
这里有个样例配置文件你可能最终会使用到:
108
170
171
+ <!--
172
+ ```yaml
173
+ apiVersion: kubelet.config.k8s.io/v1
174
+ kind: CredentialProviderConfig
175
+ # providers is a list of credential provider helper plugins that will be enabled by the kubelet.
176
+ # Multiple providers may match against a single image, in which case credentials
177
+ # from all providers will be returned to the kubelet. If multiple providers are called
178
+ # for a single image, the results are combined. If providers return overlapping
179
+ # auth keys, the value from the provider earlier in this list is used.
180
+ providers:
181
+ # name is the required name of the credential provider. It must match the name of the
182
+ # provider executable as seen by the kubelet. The executable must be in the kubelet's
183
+ # bin directory (set by the --image-credential-provider-bin-dir flag).
184
+ - name: ecr-credential-provider
185
+ # matchImages is a required list of strings used to match against images in order to
186
+ # determine if this provider should be invoked. If one of the strings matches the
187
+ # requested image from the kubelet, the plugin will be invoked and given a chance
188
+ # to provide credentials. Images are expected to contain the registry domain
189
+ # and URL path.
190
+ #
191
+ # Each entry in matchImages is a pattern which can optionally contain a port and a path.
192
+ # Globs can be used in the domain, but not in the port or the path. Globs are supported
193
+ # as subdomains like '*.k8s.io' or 'k8s.*.io', and top-level-domains such as 'k8s.*'.
194
+ # Matching partial subdomains like 'app*.k8s.io' is also supported. Each glob can only match
195
+ # a single subdomain segment, so `*.io` does **not** match `*.k8s.io`.
196
+ #
197
+ # A match exists between an image and a matchImage when all of the below are true:
198
+ # - Both contain the same number of domain parts and each part matches.
199
+ # - The URL path of an matchImages must be a prefix of the target image URL path.
200
+ # - If the matchImages contains a port, then the port must match in the image as well.
201
+ #
202
+ # Example values of matchImages:
203
+ # - 123456789.dkr.ecr.us-east-1.amazonaws.com
204
+ # - *.azurecr.io
205
+ # - gcr.io
206
+ # - *.*.registry.io
207
+ # - registry.io:8080/path
208
+ matchImages:
209
+ - "*.dkr.ecr.*.amazonaws.com"
210
+ - "*.dkr.ecr.*.amazonaws.com.cn"
211
+ - "*.dkr.ecr-fips.*.amazonaws.com"
212
+ - "*.dkr.ecr.us-iso-east-1.c2s.ic.gov"
213
+ - "*.dkr.ecr.us-isob-east-1.sc2s.sgov.gov"
214
+ # defaultCacheDuration is the default duration the plugin will cache credentials in-memory
215
+ # if a cache duration is not provided in the plugin response. This field is required.
216
+ defaultCacheDuration: "12h"
217
+ # Required input version of the exec CredentialProviderRequest. The returned CredentialProviderResponse
218
+ # MUST use the same encoding version as the input. Current supported values are:
219
+ # - credentialprovider.kubelet.k8s.io/v1
220
+ apiVersion: credentialprovider.kubelet.k8s.io/v1
221
+ # Arguments to pass to the command when executing it.
222
+ # +optional
223
+ # args:
224
+ # - --example-argument
225
+ # Env defines additional environment variables to expose to the process. These
226
+ # are unioned with the host's environment, as well as variables client-go uses
227
+ # to pass argument to the plugin.
228
+ # +optional
229
+ env:
230
+ - name: AWS_PROFILE
231
+ value: example_profile
232
+
233
+ # tokenAttributes is the configuration for the service account token that will be passed to the plugin.
234
+ # The credential provider opts in to using service account tokens for image pull by setting this field.
235
+ # if this field is set without the `KubeletServiceAccountTokenForCredentialProviders` feature gate enabled,
236
+ # kubelet will fail to start with invalid configuration error.
237
+ # +optional
238
+ tokenAttributes:
239
+ # serviceAccountTokenAudience is the intended audience for the projected service account token.
240
+ # +required
241
+ serviceAccountTokenAudience: "<audience for the token>"
242
+ # requireServiceAccount indicates whether the plugin requires the pod to have a service account.
243
+ # If set to true, kubelet will only invoke the plugin if the pod has a service account.
244
+ # If set to false, kubelet will invoke the plugin even if the pod does not have a service account
245
+ # and will not include a token in the CredentialProviderRequest. This is useful for plugins
246
+ # that are used to pull images for pods without service accounts (e.g., static pods).
247
+ # +required
248
+ requireServiceAccount: true
249
+ # requiredServiceAccountAnnotationKeys is the list of annotation keys that the plugin is interested in
250
+ # and that are required to be present in the service account.
251
+ # The keys defined in this list will be extracted from the corresponding service account and passed
252
+ # to the plugin as part of the CredentialProviderRequest. If any of the keys defined in this list
253
+ # are not present in the service account, kubelet will not invoke the plugin and will return an error.
254
+ # This field is optional and may be empty. Plugins may use this field to extract additional information
255
+ # required to fetch credentials or allow workloads to opt in to using service account tokens for image pull.
256
+ # If non-empty, requireServiceAccount must be set to true.
257
+ # The keys defined in this list must be unique and not overlap with the keys defined in the
258
+ # optionalServiceAccountAnnotationKeys list.
259
+ # +optional
260
+ requiredServiceAccountAnnotationKeys:
261
+ - "example.com/required-annotation-key-1"
262
+ - "example.com/required-annotation-key-2"
263
+ # optionalServiceAccountAnnotationKeys is the list of annotation keys that the plugin is interested in
264
+ # and that are optional to be present in the service account.
265
+ # The keys defined in this list will be extracted from the corresponding service account and passed
266
+ # to the plugin as part of the CredentialProviderRequest. The plugin is responsible for validating the
267
+ # existence of annotations and their values. This field is optional and may be empty.
268
+ # Plugins may use this field to extract additional information required to fetch credentials.
269
+ # The keys defined in this list must be unique and not overlap with the keys defined in the
270
+ # requiredServiceAccountAnnotationKeys list.
271
+ # +optional
272
+ optionalServiceAccountAnnotationKeys:
273
+ - "example.com/optional-annotation-key-1"
274
+ - "example.com/optional-annotation-key-2"
275
+ ```
276
+ -->
109
277
``` yaml
110
278
apiVersion : kubelet.config.k8s.io/v1
111
279
kind : CredentialProviderConfig
@@ -165,6 +333,44 @@ providers:
165
333
env :
166
334
- name : AWS_PROFILE
167
335
value : example_profile
336
+
337
+ # tokenAttributes 是将传递给插件的服务账号令牌的配置。
338
+ # 凭证提供者通过设置此字段选择使用服务账号令牌进行镜像拉取。
339
+ # 如果在未启用 `KubeletServiceAccountTokenForCredentialProviders` 特性门控的情况下设置了此字段,
340
+ # kubelet 将因无效配置错误而无法启动。
341
+ # 可选
342
+ tokenAttributes :
343
+ # serviceAccountTokenAudience 是 projected service account token 的预期受众。
344
+ # 必需
345
+ serviceAccountTokenAudience : " <audience for the token>"
346
+ # requireServiceAccount 指示插件是否需要 Pod 拥有服务帐号。
347
+ # 如果设置为 true,kubelet 仅在 Pod 拥有服务账号时才会调用插件。
348
+ # 如果设置为 false,即使 Pod 没有服务账号,kubelet 也会调用插件,
349
+ # 并且不会在 CredentialProviderRequest 中包含令牌。这对于用于拉取没有服务账号的 Pod(例如静态 Pod)镜像的插件非常有用。
350
+ # 必需
351
+ requireServiceAccount : true
352
+ # requiredServiceAccountAnnotationKeys 是插件感兴趣的注解键列表,
353
+ # 并且这些键需要存在于服务帐号中。
354
+ # 在此列表中定义的键将从相应的服务帐号中提取,并作为 CredentialProviderRequest 的一部分传递给插件。
355
+ # 如果此列表中定义的任何一个键不存在于 service account 中,kubelet 将不会调用插件并返回错误。
356
+ # 此字段是可选的,可以为空。插件可以使用此字段提取获取凭据所需的额外信息,
357
+ # 或允许工作负载选择使用服务帐号令牌进行镜像拉取。
358
+ # 如果非空,则 requireServiceAccount 必须设置为 true。
359
+ # 此列表中定义的键必须唯一且不与 optionalServiceAccountAnnotationKeys 列表中定义的键重叠。
360
+ # 可选
361
+ requiredServiceAccountAnnotationKeys :
362
+ - " example.com/required-annotation-key-1"
363
+ - " example.com/required-annotation-key-2"
364
+ # optionalServiceAccountAnnotationKeys 是插件感兴趣的注解键列表,
365
+ # 并且这些键在服务帐号中是可选存在的。
366
+ # 在此列表中定义的键将从相应的 service account 中提取,并作为 CredentialProviderRequest 的一部分传递给插件。
367
+ # 插件负责验证注解及其值的存在性。此字段是可选的,可以为空。
368
+ # 插件可以使用此字段提取获取凭据所需的额外信息。
369
+ # 此列表中定义的键必须唯一且不与 requiredServiceAccountAnnotationKeys 列表中定义的键重叠。
370
+ # 可选
371
+ optionalServiceAccountAnnotationKeys :
372
+ - " example.com/optional-annotation-key-1"
373
+ - " example.com/optional-annotation-key-2"
168
374
` ` `
169
375
170
376
<!--
@@ -193,6 +399,46 @@ Consult the plugin implementors to determine what set of arguments and environme
193
399
每个凭据提供程序也可以被赋予可选的参数和环境变量。
194
400
你可以咨询插件实现者以确定给定插件需要哪些参数和环境变量集。
195
401
402
+ <!--
403
+ If you are using the KubeletServiceAccountTokenForCredentialProviders feature gate
404
+ and configuring the plugin to use the service account token
405
+ by setting the tokenAttributes field,
406
+ the following fields are required :
407
+ -->
408
+ 如果你正在使用 KubeletServiceAccountTokenForCredentialProviders 特性门控
409
+ 并且通过设置 tokenAttributes 字段配置插件使用服务帐号令牌,
410
+ 那么需要以下字段:
411
+
412
+ <!--
413
+ * `serviceAccountTokenAudience`:
414
+ the intended audience for the projected service account token.
415
+ This cannot be the empty string.
416
+ * `requireServiceAccount`:
417
+ whether the plugin requires the pod to have a service account.
418
+ * If set to `true`, kubelet will only invoke the plugin
419
+ if the pod has a service account.
420
+ * If set to `false`, kubelet will invoke the plugin
421
+ even if the pod does not have a service account
422
+ and will not include a token in the `CredentialProviderRequest`.
423
+
424
+ This is useful for plugins that are used
425
+ to pull images for pods without service accounts
426
+ (e.g., static pods).
427
+ -->
428
+ * `serviceAccountTokenAudience`:
429
+ 预期的投射服务帐号令牌的受众。
430
+ 这不能是空字符串。
431
+
432
+ * `requireServiceAccount`:
433
+ 插件是否要求 Pod 拥有服务帐号。
434
+ - 如果设置为 `true`,kubelet 只会在 Pod 拥有 service account 时
435
+ 调用插件。
436
+ - 如果设置为 `false`,即使 Pod 没有服务帐号,
437
+ kubelet 也会调用插件,并且不会在 `CredentialProviderRequest` 中包含令牌。
438
+
439
+ 这对于用于拉取没有服务帐号的 Pod 的镜像的插件非常有用
440
+ (例如,静态 Pod)。
441
+
196
442
<!--
197
443
# ### Configure image matching
198
444
0 commit comments