如何提供对服务帐户的访问权限以读取多个命名空间中的 pod?

not*_*low 2 rbac kubernetes kubectl

我将讨论 Kubernetes 中的 RBAC。在我看来

  • ServiceAccount 可以绑定到命名空间(或)内的角色
  • ServiceAccount 可以绑定到 ClusterRole 并具有集群范围的访问权限(所有命名空间?)

单个服务帐户(或用户)是否可以不具有集群范围的访问权限,而只能在命名空间的子集中具有只读访问权限?如果是这样,有人可以详细说明如何实现这一目标。谢谢!

Luk*_*ler 7

您需要为 ServiceAccount 应有权访问的每个命名空间中的每个命名空间创建 RoleBinding。

有一个示例,授予默认 ServiceAccount 读取development命名空间中 pod 的权限。

kind: RoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: read-secrets
  namespace: development # This only grants permissions within the "development" namespace.
subjects:
- kind: ServiceAccount
  name: default
  namespace: kube-system
roleRef:
  kind: Role
  name: pod-reader 
  apiGroup: rbac.authorization.k8s.io
Run Code Online (Sandbox Code Playgroud)