Failed to list *v1.StorageClass: storageclasses.storage.k8s.io is forbidden: User "system:serviceaccount:default:nfs-client-provisioner" cannot list resource "storageclasses" in API group "storage.k8s.io" at the cluster scope: RBAC: clusterrole.rbac.authorization.k8s.io "nfs-client-provisioner-role" not found的yaml怎么写
时间: 2024-03-23 15:38:21 浏览: 162
php错误提示failed to open stream: HTTP request failed!的完美解决方法
您可以尝试创建一个新的 ClusterRole 来授权您的 ServiceAccount 访问存储类资源。具体操作步骤如下:
1. 创建一个新的 ClusterRole,例如:
```
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: nfs-client-provisioner-role
rules:
- apiGroups: [""]
resources: ["persistentvolumes", "persistentvolumeclaims", "services"]
verbs: ["get", "list", "watch", "create", "update", "delete"]
- apiGroups: ["storage.k8s.io"]
resources: ["storageclasses"]
verbs: ["get", "list", "watch"]
```
2. 授权给您的 ServiceAccount,例如:
```
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: nfs-client-provisioner-binding
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: nfs-client-provisioner-role
subjects:
- kind: ServiceAccount
name: nfs-client-provisioner
namespace: default
```
3. 检查您的 ServiceAccount 是否已经获得了新的权限,例如:
```
kubectl auth can-i list storageclasses --as=system:serviceaccount:default:nfs-client-provisioner
```
如果返回结果为 `yes`,则说明您的 ServiceAccount 已经获得了访问存储类资源的权限。
阅读全文