以下代码是 Kubernetes 中的 RBAC(Role-Based Access Control)配置,用于授权 ServiceAccount 'prometheus-k8s' 在 'ideal-vgpu' 命名空间中访问指定资源的权限。

第一段代码:定义 ClusterRole

apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: pod-reader
rules:
- apiGroups: [""]
  resources: ['services', 'deployments', 'pods', 'endpoints']
  verbs: ['get', 'watch', 'list']

这段代码定义了一个 ClusterRole 'pod-reader',它授权访问 'services'、'deployments'、'pods' 和 'endpoints' 资源的 'get'、'watch' 和 'list' 操作。

第二段代码:定义 RoleBinding

apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
  name: pod-reader-binding
  namespace: ideal-vgpu
subjects:
- kind: ServiceAccount
  name: prometheus-k8s
  namespace: monitoring
roleRef:
  kind: ClusterRole
  name: pod-reader
  apiGroup: rbac.authorization.k8s.io

这段代码定义了一个 RoleBinding 'pod-reader-binding',它将 ClusterRole 'pod-reader' 授权绑定到了 ServiceAccount 'prometheus-k8s' 上,并限定了其作用域为 'ideal-vgpu' 命名空间。这样 'prometheus-k8s' 就可以在 'ideal-vgpu' 命名空间中访问这些资源了。

Kubernetes RBAC 配置:授权 ServiceAccount 访问资源

原文地址: https://www.cveoy.top/t/topic/kwsF 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录