首页 > 解决方案 > 一个 Kubernetes 仪表板,用于多个选定的命名空间

问题描述

我们的集群中有多个命名空间。管理员可以通过 ClusterRole 访问所有命名空间。但是,用户将被授予访问相应命名空间的权限。

假设用户 A 被授予对命名空间 B、C 和 D 的访问权限。

因此,用户 A 使用服务帐户和 RoleBinding 在命名空间 B 中部署仪表板。用户将能够看到命名空间 B 中的所有应用程序。但是,我们如何授予对该仪表板的访问权限,以便一个仪表板将列出 3 个命名空间以查看相应的应用程序?

标签: kubernetes

解决方案


在当前版本的Kubernetes中,不同的用户可以管理不同的命名空间。您需要了解RBAC的工作原理以及如何使用它来管理多个仪表板

概念草案:您需要创建规则、角色和授予权限(集群范围和所有命名空间),然后进行角色绑定。它可用于授予对任何特定命名空间或所有命名空间中资源的读取访问权限。

例如,这里是如何将用户“jane”绑定到默认命名空间并将用户“dave”绑定到开发团队。您可以在两个命名空间中提供 Dashboard 以授予单个用户对它们的访问权限。

# This role binding allows "jane" to read pods in the "default" namespace.
kind: RoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: read-pods
  namespace: default
subjects:
- kind: User
  name: jane # Name is case sensitive
  apiGroup: rbac.authorization.k8s.io
roleRef:
  kind: Role #this must be Role or ClusterRole
  name: pod-reader # this must match the name of the Role or ClusterRole you wish to bind to
  apiGroup: rbac.authorization.k8s.io

   # This role binding allows "dave" to read secrets in the "development" namespace.
kind: RoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: read-secrets
  namespace: development # This only grants permissions within the "development" namespace.
subjects:
- kind: User
  name: dave # Name is case sensitive
  apiGroup: rbac.authorization.k8s.io
roleRef:
  kind: ClusterRole
  name: secret-reader
  apiGroup: rbac.authorization.k8s.io

推荐阅读