在k8s1.23版本种,我要添加logs,describe ,get ,exec, edit的权限给一个完整的role 的case
时间: 2024-09-23 13:12:21 浏览: 31
k8s 1.23.8部署使用完整包
在 Kubernetes (k8s) 1.23 版本中,如果你想要为一个 Role 添加 logs、describe、get、exec 和 edit 的权限,你需要创建一个 RoleBinding 或 ClusterRoleBinding 来关联这个 Role,并指定相应的权限。这里是一个示例:
1. **创建 Role**(假设你想创建名为 "my-app-admin" 的 Role)
```yaml
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: my-app-admin
rules:
- apiGroups: ["logs", ""]
resources: ["logs"]
verbs: ["get", "list", "watch"]
- apiGroup: ""
resources:
- pods
- services
verbs:
- get
- describe
- apiGroup: apps
resourceNames: ["myapp-deployment"] # 如果你要限制到特定资源名
resources: ["pods"]
verbs: ["exec"]
- apiGroup: batch
resources: ["jobs"]
verbs: ["edit"]
```
2. **创建 RoleBinding**(如果是在命名空间内)
```yaml
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: my-app-admin-binding
namespace: my-namespace
subjects:
- kind: User
name: user1
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: my-app-admin
```
3. **创建 ClusterRoleBinding**(如果是要在集群级别)
```yaml
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: my-app-admin-cluster-binding
subjects:
- kind: ServiceAccount
name: default # 或者你所需的ServiceAccount名称
namespace: default
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: my-app-admin
```
4. **验证权限**
完成上述配置后,用户 `user1`(或服务账户 `default`)将拥有执行指定操作的权限。
阅读全文