1
1
---
2
- title : 管理 Service Accounts
2
+ title : 管理服务账号
3
3
content_type : concept
4
4
weight : 50
5
5
---
@@ -20,7 +20,7 @@ weight: 50
20
20
This is a Cluster Administrator guide to service accounts. You should be familiar with
21
21
[configuring Kubernetes service accounts](/docs/tasks/configure-pod-container/configure-service-account/).
22
22
23
- Support for authorization and user accounts is planned but incomplete. Sometimes
23
+ Support for authorization and user accounts is planned but incomplete. Sometimes
24
24
incomplete features are referred to in order to better describe service accounts.
25
25
-->
26
26
这是一篇针对服务账号的集群管理员指南。你应该熟悉
@@ -102,41 +102,98 @@ It acts synchronously to modify pods as they are created or updated. When this p
102
102
或更新时它会进行以下操作:
103
103
104
104
<!--
105
- 1. If the pod does not have a `serviceAccountName` set, it sets the
106
- `serviceAccountName` to `default`.
107
- 1. It ensures that the `serviceAccountName` referenced by the pod exists, and
108
- otherwise rejects it.
109
- 1. If the pod does not contain any `imagePullSecrets`, then `imagePullSecrets`
110
- of the ServiceAccount referenced by `serviceAccountName` are added to the pod.
105
+ 1. If the pod does not have a `ServiceAccount` set, it sets the `ServiceAccount` to `default`.
106
+ 1. It ensures that the `ServiceAccount` referenced by the pod exists, and otherwise rejects it.
111
107
1. It adds a `volume` to the pod which contains a token for API access
112
108
if neither the ServiceAccount `automountServiceAccountToken` nor the Pod's
113
109
`automountServiceAccountToken` is set to `false`.
114
110
1. It adds a `volumeSource` to each container of the pod mounted at
115
111
`/var/run/secrets/kubernetes.io/serviceaccount`, if the previous step has
116
112
created a volume for ServiceAccount token.
113
+ 1. If the pod does not contain any `ImagePullSecrets`, then `ImagePullSecrets` of the `ServiceAccount` are added to the pod.
117
114
-->
118
- 1 . 如果该 Pod 没有设置 ` serviceAccountName ` ,将其 ` serviceAccountName ` 设为
119
- ` default ` 。
120
- 1 . 保证 Pod 所引用的 ` serviceAccountName ` 确实存在,否则拒绝该 Pod。
121
- 1 . 如果 Pod 不包含 ` imagePullSecrets ` 设置,将 ` serviceAccountName ` 所引用
122
- 的服务账号中的 ` imagePullSecrets ` 信息添加到 Pod 中。
115
+ 1 . 如果该 Pod 没有设置 ` ServiceAccount ` ,将其 ` ServiceAccount ` 设为 ` default ` 。
116
+ 1 . 保证 Pod 所引用的 ` ServiceAccount ` 确实存在,否则拒绝该 Pod。
123
117
1 . 如果服务账号的 ` automountServiceAccountToken ` 或 Pod 的
124
118
` automountServiceAccountToken ` 都为设置为 ` false ` ,则为 Pod 创建一个
125
119
` volume ` ,在其中包含用来访问 API 的令牌。
126
120
1 . 如果前一步中为服务账号令牌创建了卷,则为 Pod 中的每个容器添加一个
127
121
` volumeSource ` ,挂载在其 ` /var/run/secrets/kubernetes.io/serviceaccount `
128
122
目录下。
123
+ 1 . 如果 Pod 不包含 ` imagePullSecrets ` 设置,将 ` ServiceAccount ` 所引用
124
+ 的服务账号中的 ` imagePullSecrets ` 信息添加到 Pod 中。
125
+
126
+ <!--
127
+ #### Bound Service Account Token Volume
128
+ -->
129
+ #### 绑定的服务账号令牌卷 {#bound-service-account-token-volume}
130
+
131
+
132
+ {{< feature-state for_k8s_version="v1.21" state="beta" >}}
129
133
130
134
<!--
131
- You can migrate a service account volume to a projected volume when
132
- the `BoundServiceAccountTokenVolume` feature gate is enabled.
133
- The service account token will expire after 1 hour or the pod is deleted. See
134
- more details about
135
- [projected volume](/docs/tasks/configure-pod-container/configure-projected-volume-storage/).
135
+ When the `BoundServiceAccountTokenVolume` [feature gate](/docs/reference/command-line-tools-reference/feature-gates/) is enabled, the service account admission controller will
136
+ add the following projected volume instead of a Secret-based volume for the non-expiring service account token created by Token Controller.
136
137
-->
137
- 当 ` BoundServiceAccountTokenVolume ` 特性门控被启用时,你可以将服务账号卷迁移到投射卷。
138
- 服务账号令牌会在 1 小时后或者 Pod 被删除之后过期。
139
- 更多信息可参阅[ 投射卷] ( /zh/docs/tasks/configure-pod-container/configure-projected-volume-storage/ ) 。
138
+ 当 ` BoundServiceAccountTokenVolume `
139
+ [ 特性门控] ( /zh/docs/reference/command-line-tools-reference/feature-gates/ )
140
+ 被启用时,服务账号准入控制器将添加如下投射卷,而不是为令牌控制器
141
+ 所生成的不过期的服务账号令牌而创建的基于 Secret 的卷。
142
+
143
+ ``` yaml
144
+ - name : kube-api-access-<随机后缀>
145
+ projected :
146
+ defaultMode : 420 # 0644
147
+ sources :
148
+ - serviceAccountToken :
149
+ expirationSeconds : 3600
150
+ path : token
151
+ - configMap :
152
+ items :
153
+ - key : ca.crt
154
+ path : ca.crt
155
+ name : kube-root-ca.crt
156
+ - downwardAPI :
157
+ items :
158
+ - fieldRef :
159
+ apiVersion : v1
160
+ fieldPath : metadata.namespace
161
+ path : namespace
162
+ ` ` `
163
+
164
+ <!--
165
+ This projected volume consists of three sources:
166
+
167
+ 1. A ServiceAccountToken acquired from kube-apiserver via TokenRequest API. It will expire after 1 hour by default or when the pod is deleted. It is bound to the pod and has kube-apiserver as the audience.
168
+ 1. A ConfigMap containing a CA bundle used for verifying connections to the kube-apiserver. This feature depends on the ` RootCAConfigMap` feature gate being enabled, which publishes a "kube-root-ca.crt" ConfigMap to every namespace. `RootCAConfigMap` is enabled by default in 1.20, and always enabled in 1.21+.
169
+ 1. A DownwardAPI that references the namespace of the pod.
170
+ -->
171
+ 此投射卷有三个数据源:
172
+
173
+ 1. 通过 TokenRequest API 从 kube-apiserver 处获得的 ServiceAccountToken。
174
+ 这一令牌默认会在一个小时之后或者 Pod 被删除时过期。
175
+ 该令牌绑定到 Pod 实例上,并将 kube-apiserver 作为其受众(audience)。
176
+ 1. 包含用来验证与 kube-apiserver 连接的 CA 证书包的 ConfigMap 对象。
177
+ 这一特性依赖于 `RootCAConfigMap` 特性门控被启用。该特性被启用时,
178
+ 控制面会公开一个名为 `kube-root-ca.crt` 的 ConfigMap 给所有名字空间。
179
+ ` RootCAConfigMap` 在 1.20 版本中是默认被启用的,在 1.21 及之后版本中
180
+ 总是被启用。
181
+ 1. 引用 Pod 名字空间的一个 DownwardAPI。
182
+
183
+ <!--
184
+ See more details about [projected volumes](/docs/tasks/configure-pod-container/configure-projected-volume-storage/).
185
+
186
+ You can manually migrate a secret-based service account volume to a projected volume when
187
+ the `BoundServiceAccountTokenVolume` feature gate is not enabled by adding the above
188
+ projected volume to the pod spec. However, `RootCAConfigMap` needs to be enabled.
189
+ -->
190
+ 参阅[投射卷](/zh/docs/tasks/configure-pod-container/configure-projected-volume-storage/)
191
+ 了解进一步的细节。
192
+
193
+ 如果 `BoundServiceAccountTokenVolume` 特性门控未被启用,
194
+ 你可以手动地将一个基于 Secret 的服务账号卷升级为一个投射卷,
195
+ 方法是将上述投射卷添加到 Pod 规约中。
196
+ 不过,这时仍需要启用 `RootCAConfigMap` 特性门控。
140
197
141
198
<!--
142
199
# ## Token Controller
0 commit comments