我可以将一个服务帐户连接到 Kubernetes 中的多个命名空间吗?



我有几个命名空间 - 假设NS1NS2。我在那些中创建了服务帐户 - sa1NS1 年,sa2NS2.我已经为sa1创建了角色和角色绑定,以便在NS1中做事,并在NS2sa2。我想要的是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

最新更新