ClusterRole的规则
ClusterRole对象的rules字段定义了该角色允许访问的API组、资源和操作。rules字段包含一个或多个规则,每个规则定义了一组API组、资源和操作。下面是一个规则的示例:
代码语言:javascript复制kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: pod-reader
rules:
- apiGroups: [""]
resources: ["pods"]
verbs: ["get", "watch", "list"]
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: pod-reader-sa
---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: pod-reader-binding
subjects:
- kind: ServiceAccount
name: pod-reader-sa
namespace: default
roleRef:
kind: ClusterRole
name: pod-reader
apiGroup: rbac.authorization.k8s.io
在上面的示例中,我们创建了一个ClusterRole对象“pod-reader”,它允许用户对所有命名空间中的Pod对象执行get、watch和list操作。然后,我们创建了一个ServiceAccount对象“pod-reader-sa”,它将使用该ClusterRole进行授权。最后,我们创建了一个ClusterRoleBinding对象,将ClusterRole“pod-reader”绑定到ServiceAccount“pod-reader-sa”。