我正在尝试授予只读 iam 角色对集群的只读访问权限。为此,我创建了一个服务帐户、集群角色和集群角色绑定。 但是,在使用 readonly iam 角色访问 kubectl get pods 时,它给了我以下错误:
pods 被禁止:用户“readonly”不能在命名空间“kube-system”中的API组“”中列出资源“pods”
请帮我解决这个错误。
集群角色:
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: readrole
namespace: kube-system
rules:
- apiGroups:
- ""
resources:
- '*'
verbs:
- get
- list
- watch
- apiGroups:
- extensions
resources:
- '*'
verbs:
- get
- list
- watch
- apiGroups:
- apps
resources:
- '*'
verbs:
- get
- list
- watch
服务帐户:
kubectl create sa readonly -n kube-system
创建集群角色绑定
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: readrole-binding
namespace: kube-system
subjects:
- kind: ServiceAccount
name: readonly
namespace: kube-system
roleRef:
kind: ClusterRole
name: readrole
apiGroup: rbac.authorization.k8s.io
另外,如果使用 kubernetes 提供的默认角色也有另一种方法,请告诉我。