一个 Kubernetes 仪表板用于多个选定的命名空间



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

比如说,用户 A 有权访问命名空间 B、C 和 D。

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

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

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

例如,下面介绍如何将用户"jane"绑定到默认命名空间,将用户"dave"绑定到开发团队。 可以在两个命名空间中提供仪表板,以授予单个用户对它们的访问权限。

# 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

最新更新