我有几个命名空间 - 假设NS1
和NS2
。我在那些中创建了服务帐户 - sa1
在 NS1
年,sa2
在NS2
.我已经为sa1
创建了角色和角色绑定,以便在NS1
中做事,并在NS2
中sa2
。我想要的是sa1
NS2
内授予某些访问权限(仅说 Pod 读取者角色)。
我想知道这是否可能?
只需从角色绑定中的另一个命名空间引用服务帐户:
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: Role
metadata:
name: pod-reader
namespace: ns2
rules:
- apiGroups: [""]
resources: ["pods"]
verbs: ["get", "list", "watch"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: pod-reader-from-ns1
namespace: ns2
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: pod-reader
subjects:
- kind: ServiceAccount
name: ns1-service-account
namespace: ns1