# 只授权了 michael namespace的对pod的 list get watch 权限
[root@michael-00359-drome rbac]# kubectl get pods
No resources found.
Error from server (Forbidden): pods is forbidden: User "system:serviceaccount:michael:hzeng" cannot list pods in the namespace "default"
# 非michael的namespace 的pod操作直接forbidden
[root@michael-00359-drome rbac]# kubectl get pods -n michael
No resources found.
[root@michael-00359-drome rbac]# kubectl get svc -n michael
No resources found.
Error from server (Forbidden): services is forbidden: User "system:serviceaccount:michael:hzeng" cannot list services in the namespace "michael"
添加用户对 svc的操作 管理员下面
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: handpay-pod-reader
namespace: michael
rules:
- apiGroups:
- ""
resources:
- pods
- services #添加对应的资源就可以了
verbs:
- get
- list
- watch
验证结果
[root@michael-00359-drome rbac]# kubectl get svc -n michael
No resources found.
[root@michael-00359-drome rbac]# kubectl get svc
No resources found.
Error from server (Forbidden): services is forbidden: User "system:serviceaccount:michael:hzeng" cannot list services in the namespace "default"