1
1
---
2
- title : 为 Pod 配置服务账户
2
+ title : 为 Pod 配置服务账号
3
3
content_type : task
4
4
weight : 90
5
5
---
@@ -23,10 +23,10 @@ as recommended by the Kubernetes project. Your cluster administrator may have
23
23
customized the behavior in your cluster, in which case this documentation may
24
24
not apply.
25
25
-->
26
- 服务账户为 Pod 中运行的进程提供了一个标识。
26
+ 服务账号为 Pod 中运行的进程提供了一个标识。
27
27
28
28
{{< note >}}
29
- 本文是服务账户的用户使用介绍,描述服务账户在集群中如何起作用 。
29
+ 本文是服务账号的用户使用介绍,描述服务账号在集群中如何起作用 。
30
30
你的集群管理员可能已经对你的集群做了定制,因此导致本文中所讲述的内容并不适用。
31
31
{{< /note >}}
32
32
@@ -37,9 +37,9 @@ usually `admin`, unless your cluster administrator has customized your cluster).
37
37
When they do, they are authenticated as a particular Service Account (for example, `default`).
38
38
-->
39
39
当你(自然人)访问集群时(例如,使用 ` kubectl ` ),API 服务器将你的身份验证为
40
- 特定的用户帐户 (当前这通常是 ` admin ` ,除非你的集群管理员已经定制了你的集群配置)。
41
- Pod 内的容器中的进程也可以与 api 服务器接触。
42
- 当它们进行身份验证时,它们被验证为特定的服务帐户 (例如,` default ` )。
40
+ 特定的用户账号 (当前这通常是 ` admin ` ,除非你的集群管理员已经定制了你的集群配置)。
41
+ Pod 内的容器中的进程也可以与 API 服务器接触。
42
+ 当它们进行身份验证时,它们被验证为特定的服务账号 (例如,` default ` )。
43
43
44
44
## {{% heading "prerequisites" %}}
45
45
@@ -56,9 +56,9 @@ If you get the raw json or yaml for a pod you have created (for example, `kubect
56
56
you can see the `spec.serviceAccountName` field has been
57
57
[automatically set](/docs/concepts/overview/working-with-objects/object-management/).
58
58
-->
59
- ## 使用默认的服务账户访问 API 服务器
59
+ ## 使用默认的服务账号访问 API 服务器
60
60
61
- 当你创建 Pod 时,如果没有指定服务账户 ,Pod 会被指定给命名空间中的 ` default ` 服务账户 。
61
+ 当你创建 Pod 时,如果没有指定服务账号 ,Pod 会被指定给命名空间中的 ` default ` 服务账号 。
62
62
如果你查看 Pod 的原始 JSON 或 YAML(例如:` kubectl get pods/<podname> -o yaml ` ),
63
63
你可以看到 ` spec.serviceAccountName ` 字段已经被[ 自动设置] ( /zh-cn/docs/concepts/overview/working-with-objects/object-management/ ) 了。
64
64
@@ -70,13 +70,13 @@ The API permissions of the service account depend on the
70
70
71
71
You can opt out of automounting API credentials on `/var/run/secrets/kubernetes.io/serviceaccount/token` for a service account by setting `automountServiceAccountToken: false` on the ServiceAccount:
72
72
-->
73
- 你可以使用自动挂载给 Pod 的服务账户凭据访问 API,
73
+ 你可以使用自动挂载给 Pod 的服务账号凭据访问 API,
74
74
[ 访问集群] ( /zh-cn/docs/tasks/access-application-cluster/access-cluster ) 页面中有相关描述。
75
- 服务账户的 API 许可取决于你所使用的
76
- [ 鉴权插件和策略] ( /zh-cn/docs/reference/access-authn-authz/authorization/#authorization-modules ) 。
75
+ 服务账号的 API
76
+ 许可取决于你所使用的 [ 鉴权插件和策略] ( /zh-cn/docs/reference/access-authn-authz/authorization/#authorization-modules ) 。
77
77
78
78
你可以通过在 ServiceAccount 上设置 ` automountServiceAccountToken: false `
79
- 来实现不给服务账户自动挂载 API 凭据到 ` /var/run/secrets/kubernetes.io/serviceaccount/token `
79
+ 来实现不给服务账号自动挂载 API 凭据到 ` /var/run/secrets/kubernetes.io/serviceaccount/token `
80
80
的目的:
81
81
82
82
``` yaml
@@ -107,18 +107,18 @@ spec:
107
107
<!--
108
108
The pod spec takes precedence over the service account if both specify a `automountServiceAccountToken` value.
109
109
-->
110
- 如果 Pod 和服务账户都指定了 ` automountServiceAccountToken ` 值,则 Pod 的 spec 优先于服务帐户 。
110
+ 如果 Pod 和服务账号都指定了 ` automountServiceAccountToken ` 值,则 Pod 的 spec 优先于服务账号 。
111
111
112
112
<!--
113
113
## Use Multiple Service Accounts
114
114
115
115
Every namespace has a default service account resource called `default`.
116
116
You can list this and any other serviceAccount resources in the namespace with this command:
117
117
-->
118
- ## 使用多个服务账户 {#use-multiple-service-accounts}
118
+ ## 使用多个服务账号 {#use-multiple-service-accounts}
119
119
120
- 每个命名空间都有一个名为 ` default ` 的服务账户资源 。
121
- 你可以用下面的命令查询这个服务账户以及命名空间中的其他 ServiceAccount 资源:
120
+ 每个命名空间都有一个名为 ` default ` 的服务账号资源 。
121
+ 你可以用下面的命令查询这个服务账号以及命名空间中的其他 ServiceAccount 资源:
122
122
123
123
``` shell
124
124
kubectl get serviceaccounts
@@ -158,7 +158,7 @@ ServiceAccount 对象的名字必须是一个有效的
158
158
<!--
159
159
If you get a complete dump of the service account object, like this:
160
160
-->
161
- 如果你查询服务帐户对象的完整信息 ,如下所示:
161
+ 如果你查询服务账号对象的完整信息 ,如下所示:
162
162
163
163
``` shell
164
164
kubectl get serviceaccounts/build-robot -o yaml
@@ -178,23 +178,17 @@ metadata:
178
178
namespace : default
179
179
resourceVersion : " 272500"
180
180
uid : 721ab723-13bc-11e5-aec2-42010af0021e
181
- secrets :
182
- - name : build-robot-token-bvbk5
183
181
` ` `
184
182
185
183
<!--
186
- then you will see that a token has automatically been created and is referenced by the service account.
187
-
188
184
You may use authorization plugins to [set permissions on service accounts](/docs/reference/access-authn-authz/rbac/#service-account-permissions).
189
185
190
186
To use a non-default service account, set the ` spec.serviceAccountName`
191
187
field of a pod to the name of the service account you wish to use.
192
188
-->
193
- 那么你就能看到系统已经自动创建了一个令牌并且被服务账户所引用。
194
-
195
- 你可以使用授权插件来[设置服务账户的访问许可](/zh-cn/docs/reference/access-authn-authz/rbac/#service-account-permissions)。
189
+ 你可以使用授权插件来[设置服务账号的访问许可](/zh-cn/docs/reference/access-authn-authz/rbac/#service-account-permissions)。
196
190
197
- 要使用非默认的服务账户 ,将 Pod 的 `spec.serviceAccountName` 字段设置为你想用的服务账户名称 。
191
+ 要使用非默认的服务账号 ,将 Pod 的 `spec.serviceAccountName` 字段设置为你想用的服务账号名称 。
198
192
199
193
<!--
200
194
The service account has to exist at the time the pod is created, or it will be rejected.
@@ -203,11 +197,11 @@ You cannot update the service account of an already created pod.
203
197
204
198
You can clean up the service account from this example like this :
205
199
-->
206
- Pod 被创建时服务账户必须存在 ,否则会被拒绝。
200
+ Pod 被创建时服务账号必须存在 ,否则会被拒绝。
207
201
208
- 你不能更新已经创建好的 Pod 的服务账户 。
202
+ 你不能更新已经创建好的 Pod 的服务账号 。
209
203
210
- 你可以清除服务账户 ,如下所示:
204
+ 你可以清除服务账号 ,如下所示:
211
205
212
206
` ` ` shell
213
207
kubectl delete serviceaccount/build-robot
@@ -219,9 +213,9 @@ kubectl delete serviceaccount/build-robot
219
213
Suppose we have an existing service account named "build-robot" as mentioned above, and we create
220
214
a new secret manually.
221
215
-->
222
- # # 手动创建服务账户 API 令牌
216
+ # # 手动创建服务账号 API 令牌
223
217
224
- 假设我们有一个上面提到的名为 "build-robot" 的服务账户 ,现在我们手动创建一个新的 Secret。
218
+ 假设我们有一个上面提到的名为 "build-robot" 的服务账号 ,现在我们手动创建一个新的 Secret。
225
219
226
220
` ` ` shell
227
221
kubectl apply -f - <<EOF
@@ -240,8 +234,8 @@ Now you can confirm that the newly built secret is populated with an API token f
240
234
241
235
Any tokens for non-existent service accounts will be cleaned up by the token controller.
242
236
-->
243
- 现在,你可以确认新构建的 Secret 中填充了 "build-robot" 服务帐户的 API 令牌。
244
- 令牌控制器将清理不存在的服务帐户的所有令牌 。
237
+ 现在,你可以确认新构建的 Secret 中填充了 "build-robot" 服务账号的 API 令牌。
238
+ 令牌控制器将清理不存在的服务账号的所有令牌 。
245
239
246
240
` ` ` shell
247
241
kubectl describe secrets/build-robot-secret
@@ -282,7 +276,7 @@ The content of `token` is elided here.
282
276
283
277
- Create an imagePullSecret, as described in [Specifying ImagePullSecrets on a Pod](/docs/concepts/containers/images/#specifying-imagepullsecrets-on-a-pod).
284
278
-->
285
- ## 为服务账户添加 ImagePullSecrets {#add-imagepullsecrets-to-a-service-account}
279
+ ## 为服务账号添加 ImagePullSecrets {#add-imagepullsecrets-to-a-service-account}
286
280
287
281
### 创建 ImagePullSecret
288
282
@@ -318,9 +312,9 @@ The content of `token` is elided here.
318
312
319
313
Next, modify the default service account for the namespace to use this secret as an imagePullSecret.
320
314
-->
321
- ### 将镜像拉取 Secret 添加到服务账户
315
+ ### 将镜像拉取 Secret 添加到服务账号
322
316
323
- 接着修改命名空间的 ` default ` 服务帐户 ,令其使用该 Secret 用作 ` imagePullSecret ` 。
317
+ 接着修改命名空间的 ` default ` 服务账号 ,令其使用该 Secret 用作 ` imagePullSecret ` 。
324
318
325
319
``` shell
326
320
kubectl patch serviceaccount default -p ' {"imagePullSecrets": [{"name": "myregistrykey"}]}'
@@ -350,8 +344,6 @@ metadata:
350
344
namespace : default
351
345
resourceVersion : " 243024"
352
346
uid : 052fb0f4-3d50-11e5-b066-42010af0d7b6
353
- secrets :
354
- - name : default-token-uudge
355
347
` ` `
356
348
357
349
<!--
@@ -372,16 +364,14 @@ metadata:
372
364
name: default
373
365
namespace: default
374
366
uid: 052fb0f4-3d50-11e5-b066-42010af0d7b6
375
- secrets:
376
- - name: default-token-uudge
377
367
imagePullSecrets:
378
368
- name: myregistrykey
379
369
` ` `
380
370
381
371
<!--
382
372
Finally replace the serviceaccount with the new updated `sa.yaml` file
383
373
-->
384
- 最后,使用新更新的 `sa.yaml` 文件替换服务账户 。
374
+ 最后,使用新更新的 `sa.yaml` 文件替换服务账号 。
385
375
386
376
` ` ` shell
387
377
kubectl replace serviceaccount default -f ./sa.yaml
@@ -394,7 +384,7 @@ Now, when a new Pod is created in the current namespace and using the default Se
394
384
-->
395
385
# ## 验证镜像拉取 Secret 已经被添加到 Pod 规约
396
386
397
- 现在,在当前命名空间中创建使用默认服务账户的新 Pod 时,新 Pod
387
+ 现在,在当前命名空间中创建使用默认服务账号的新 Pod 时,新 Pod
398
388
会自动设置其 `.spec.imagePullSecrets` 字段:
399
389
400
390
` ` ` shell
@@ -414,7 +404,7 @@ myregistrykey
414
404
<!--
415
405
## Service Account Token Volume Projection
416
406
-->
417
- ## 服务帐户令牌卷投射 {#service-account-token-volume-projection}
407
+ ## 服务账号令牌卷投射 {#service-account-token-volume-projection}
418
408
419
409
{{< feature-state for_k8s_version="v1.20" state="stable" >}}
420
410
@@ -431,7 +421,7 @@ command line arguments to `kube-apiserver`:
431
421
-->
432
422
* `--service-account-issuer`
433
423
434
- 此参数可作为服务账户令牌发放者的身份标识 (Identifier)。你可以多次指定
424
+ 此参数可作为服务账号令牌发放者的身份标识 (Identifier)。你可以多次指定
435
425
`--service-account-issuer` 参数,对于要变更发放者而又不想带来业务中断的场景,
436
426
这样做是有用的。如果这个参数被多次指定,则第一个参数值会被用来生成令牌,
437
427
而所有参数值都会被用来确定哪些发放者是可接受的。你所运行的 Kubernetes
@@ -454,7 +444,7 @@ command line arguments to `kube-apiserver`:
454
444
-->
455
445
* `--service-account-signing-key-file`
456
446
457
- 指向包含当前服务账户令牌发放者的私钥的文件路径 。
447
+ 指向包含当前服务账号令牌发放者的私钥的文件路径 。
458
448
此发放者使用此私钥来签署所发放的 ID 令牌。
459
449
<!--
460
450
* `--api-audiences` (can be omitted)
@@ -463,7 +453,7 @@ command line arguments to `kube-apiserver`:
463
453
-->
464
454
* `--api-audiences` (可以省略)
465
455
466
- 服务账户令牌身份检查组件会检查针对 API 访问所使用的令牌,
456
+ 服务账号令牌身份检查组件会检查针对 API 访问所使用的令牌,
467
457
确认令牌至少是被绑定到这里所给的受众(audiences)之一。
468
458
如果此参数被多次指定,则针对所给的多个受众中任何目标的令牌都会被
469
459
Kubernetes API 服务器当做合法的令牌。如果 `--service-account-issuer`
@@ -477,10 +467,10 @@ duration. These properties are not configurable on the default service account
477
467
token. The service account token will also become invalid against the API when
478
468
the Pod or the ServiceAccount is deleted.
479
469
-->
480
- kubelet 还可以将服务帐户令牌投射到 Pod 中。
470
+ kubelet 还可以将服务账号令牌投射到 Pod 中。
481
471
你可以指定令牌的期望属性,例如受众和有效期限。
482
- 这些属性在 default 服务帐户令牌上无法配置 。
483
- 当删除 Pod 或 ServiceAccount 时,服务帐户令牌也将对 API 无效。
472
+ 这些属性在 default 服务账号令牌上无法配置 。
473
+ 当删除 Pod 或 ServiceAccount 时,服务账号令牌也将对 API 无效。
484
474
485
475
<!--
486
476
This behavior is configured on a PodSpec using a ProjectedVolume type called
@@ -522,7 +512,7 @@ The application is responsible for reloading the token when it rotates. Periodic
522
512
<!--
523
513
## Service Account Issuer Discovery
524
514
-->
525
- ## 发现服务账户分发者
515
+ ## 发现服务账号分发者
526
516
527
517
{{< feature-state for_k8s_version="v1.21" state="stable" >}}
528
518
@@ -531,7 +521,7 @@ The Service Account Issuer Discovery feature is enabled when the Service Account
531
521
Token Projection feature is enabled, as described
532
522
[above](#service-account-token-volume-projection).
533
523
-->
534
- 当启用服务账户令牌投射时启用发现服务账户分发者 (Service Account Issuer Discovery)
524
+ 当启用服务账号令牌投射时启用发现服务账号分发者 (Service Account Issuer Discovery)
535
525
这一功能特性,如[ 上文所述] ( #service-account-token-volume-projection ) 。
536
526
537
527
<!--
@@ -564,9 +554,9 @@ Configuration document at `/.well-known/openid-configuration` and the associated
564
554
JSON Web Key Set (JWKS) at `/openid/v1/jwks`. The OpenID Provider Configuration
565
555
is sometimes referred to as the _discovery document_.
566
556
-->
567
- 发现服务账户分发者这一功能使得用户能够用联邦的方式结合使用 Kubernetes
557
+ 发现服务账号分发者这一功能使得用户能够用联邦的方式结合使用 Kubernetes
568
558
集群(“Identity Provider”,标识提供者)与外部系统(“Relying Parties”,
569
- 依赖方)所分发的服务账户令牌 。
559
+ 依赖方)所分发的服务账号令牌 。
570
560
571
561
当此功能被启用时,Kubernetes API 服务器会在 ` /.well-known/openid-configuration `
572
562
提供一个 OpenID 提供者配置文档,并在 ` /openid/v1/jwks ` 处提供与之关联的
@@ -585,8 +575,8 @@ requirements and which external systems they intend to federate with.
585
575
-->
586
576
集群包括一个的默认 RBAC ClusterRole, 名为 ` system:service-account-issuer-discovery ` 。
587
577
默认的 RBAC ClusterRoleBinding 将此角色分配给 ` system:serviceaccounts ` 组,
588
- 所有服务帐户隐式属于该组 。这使得集群上运行的 Pod
589
- 能够通过它们所挂载的服务帐户令牌访问服务帐户发现文档 。
578
+ 所有服务账号隐式属于该组 。这使得集群上运行的 Pod
579
+ 能够通过它们所挂载的服务账号令牌访问服务账号发现文档 。
590
580
此外,管理员可以根据其安全性需要以及期望集成的外部系统选择是否将该角色绑定到
591
581
` system:authenticated ` 或 ` system:unauthenticated ` 。
592
582
@@ -599,7 +589,7 @@ validation of Kubernetes service account tokens.
599
589
{{< note >}}
600
590
对 ` /.well-known/openid-configuration ` 和 ` /openid/v1/jwks ` 路径请求的响应被设计为与
601
591
OIDC 兼容,但不是与其完全一致。
602
- 返回的文档仅包含对 Kubernetes 服务账户令牌进行验证所必须的参数 。
592
+ 返回的文档仅包含对 Kubernetes 服务账号令牌进行验证所必须的参数 。
603
593
{{< /note >}}
604
594
605
595
<!--
@@ -608,7 +598,7 @@ the Kubernetes service account tokens. Relying parties first query for the
608
598
OpenID Provider Configuration, and use the `jwks_uri` field in the response to
609
599
find the JWKS.
610
600
-->
611
- JWKS 响应包含依赖方可以用来验证 Kubernetes 服务账户令牌的公钥数据 。
601
+ JWKS 响应包含依赖方可以用来验证 Kubernetes 服务账号令牌的公钥数据 。
612
602
依赖方先会查询 OpenID 提供者配置,之后使用返回响应中的 ` jwks_uri ` 来查找 JWKS。
613
603
614
604
<!--
@@ -639,7 +629,7 @@ See also:
639
629
-->
640
630
另请参见:
641
631
642
- - [ 服务账户的集群管理员指南 ] ( /zh-cn/docs/reference/access-authn-authz/service-accounts-admin/ )
643
- - [ 服务账户签署密钥检索 KEP] ( https://github.com/kubernetes/enhancements/tree/master/keps/sig-auth/1393-oidc-discovery )
632
+ - [ 服务账号的集群管理员指南 ] ( /zh-cn/docs/reference/access-authn-authz/service-accounts-admin/ )
633
+ - [ 服务账号签署密钥检索 KEP] ( https://github.com/kubernetes/enhancements/tree/master/keps/sig-auth/1393-oidc-discovery )
644
634
- [ OIDC 发现规范] ( https://openid.net/specs/openid-connect-discovery-1_0.html )
645
635
0 commit comments