- apiGroups: ["storage.k8s.io"] resources: ["storageclasses"] verbs: ["get", "list", "watch"] 这段代码是什么意思
时间: 2023-07-22 16:10:25 浏览: 73
这段代码是 Kubernetes 中定义 API 操作权限的一部分,用于指定对存储类资源(StorageClass)的操作权限。其中,`apiGroups` 字段指定了资源所属的 API 组,`resources` 字段指定了要操作的资源类型,`verbs` 字段指定了可以对资源执行的操作类型。
具体解释如下:
- `apiGroups: ["storage.k8s.io"]`: 表示该资源属于 `storage.k8s.io` API 组。
- `resources: ["storageclasses"]`: 表示要操作的资源类型是 `storageclasses`,即存储类资源。
- `verbs: ["get", "list", "watch"]`: 表示被授权的操作类型包括获取(读取)单个存储类的详细信息、获取存储类列表的摘要信息以及对存储类进行实时监视。
通过指定这些操作类型,您可以限制用户或服务账号对存储类资源的访问和操作权限。例如,如果某个用户或服务账号只被授予 `get` 和 `list` 权限,则它们只能读取存储类的详细信息或列表,而无法进行其他操作。
这段代码通常会作为 Kubernetes RBAC(Role-Based Access Control)规则中的一部分出现。RBAC 规则用于定义集群中不同角色的权限,并将这些角色分配给用户或服务账号,以实现细粒度的访问控制和权限管理。在这个例子中,该代码片段定义了对存储类资源的操作权限。
相关问题
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怎么写
您可以尝试创建一个新的 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 已经获得了访问存储类资源的权限。
registry.cn-beijing.aliyuncs.com/mydlq/nfs-subdir-external-provisioner:v4.0.0的k8s的yaml怎么写
下面是一个基本的 Kubernetes YAML 文件示例,可用于部署容器镜像 `registry.cn-beijing.aliyuncs.com/mydlq/nfs-subdir-external-provisioner:v4.0.0`:
```yaml
apiVersion: v1
kind: ServiceAccount
metadata:
name: nfs-subdir-external-provisioner
---
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRole
metadata:
name: nfs-subdir-external-provisioner-runner
rules:
- apiGroups: [""]
resources: ["persistentvolumes"]
verbs: ["get", "list", "watch", "create", "delete"]
- apiGroups: [""]
resources: ["persistentvolumeclaims"]
verbs: ["get", "list", "watch", "update"]
- apiGroups: ["storage.k8s.io"]
resources: ["storageclasses"]
verbs: ["get", "list", "watch"]
- apiGroups: [""]
resources: ["events"]
verbs: ["create", "update", "patch"]
---
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRoleBinding
metadata:
name: run-nfs-subdir-external-provisioner
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: nfs-subdir-external-provisioner-runner
subjects:
- kind: ServiceAccount
name: nfs-subdir-external-provisioner
namespace: default
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: nfs-subdir-external-provisioner
spec:
replicas: 1
selector:
matchLabels:
app: nfs-subdir-external-provisioner
template:
metadata:
labels:
app: nfs-subdir-external-provisioner
spec:
serviceAccountName: nfs-subdir-external-provisioner
containers:
- name: nfs-subdir-external-provisioner
image: registry.cn-beijing.aliyuncs.com/mydlq/nfs-subdir-external-provisioner:v4.0.0
env:
- name: PROVISIONER_NAME
value: nfs-subdir-external-provisioner
- name: NFS_SERVER
value: your.nfs.server.ip
- name: NFS_PATH
value: /path/to/nfs/share
volumeMounts:
- name: nfs-client-root
mountPath: /persistentvolumes
volumes:
- name: nfs-client-root
nfs:
server: your.nfs.server.ip
path: /path/to/nfs/share
```
注意替换 `NFS_SERVER` 和 `NFS_PATH` 的值为你的 NFS 服务器的 IP 地址和共享路径。同时,需要根据实际情况修改应用的名称、命名空间和其他配置。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)