This documentation is for a release that is no longer maintained
See documentation for the latest supported version 3 or the latest supported version 4.12.2. 使用卷投射配置绑定服务帐户令牌
您可以使用卷投射,将 pod 配置为请求绑定的服务帐户令牌。
先决条件
-
您可以使用具有
cluster-admin
角色的用户访问集群。 -
您已创建了一个服务帐户。这里假定服务帐户命名为
build-robot
。
流程
另外,还可选择设置服务帐户问题的签发者。
如果绑定令牌仅在集群中使用,则通常不需要这一步。
编辑
cluster
Authentication
对象:oc edit authentications cluster
$ oc edit authentications cluster
Copy to Clipboard Copied! Toggle word wrap Toggle overflow 将
spec.serviceAccountIssuer
字段设置为所需的服务帐户签发者:spec: serviceAccountIssuer: https://test.default.svc
spec: serviceAccountIssuer: https://test.default.svc
1 Copy to Clipboard Copied! Toggle word wrap Toggle overflow - 1
- 这个值应该是 URL,通过这个 URL,绑定令牌的接收方可以从中查找验证令牌签名所需的公钥。默认为
https://kubernetes.default.svc
。
使用卷投影将 pod 配置为使用绑定服务帐户令牌。
创建名为
pod-projected-svc-token.yaml
的文件,其内容如下:Copy to Clipboard Copied! Toggle word wrap Toggle overflow 创建 pod:
oc create -f pod-projected-svc-token.yaml
$ oc create -f pod-projected-svc-token.yaml
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Kubelet 代表 pod 请求并存储令牌,使 pod 可以在一个可配置的文件路径中获得令牌,并在该令牌接近到期时刷新令牌。
使用绑定令牌的应用程序需要在令牌轮转时重新载入令牌。
如果令牌使用的时间超过这个值的 80%,或者超过 24 小时,则 kubelet 会轮转令牌。