kubernetes - 无法在具有服务帐户、已创建 ClusterRole 和 ClusterRolebinding 的命名空间中创建部署
问题描述
我在练习 Security k8s 时手忙脚乱。这是我遇到的一个要解决的练习题。
问题:
创建serviceaccount
'john' 并有权在给定的namespace 'hr'
Create clusterrole and clusterrolebindings
required 中创建删除获取部署、状态集、守护程序集。
方法: 已尝试创建 sa 和 clusterrole 和 clusterrolebinding(将 clusterrole 与创建的 sa 绑定)但是当我检查它时给出“否”
kubectl auth can-i create deploy --as john -n hr
no
创建 sa:
kubectl create sa john
创建集群角色:
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
# "namespace" omitted since ClusterRoles are not namespaced
name: hrcrole
rules:
- apiGroups: ["apps"]
#
# at the HTTP level, the name of the resource for accessing Secret
# objects is "secrets"
resources: ["deployments", "statefulsets", "daemonsets"]
verbs: ["get", "watch", "list", "delete"]
创建集群角色绑定:
apiVersion: rbac.authorization.k8s.io/v1
# This cluster role binding allows anyone in the "manager" group to read secrets in any namespace.
kind: ClusterRoleBinding
metadata:
name: hrcrolebind
subjects:
- kind: User
name: hruser # Name is case sensitive
apiGroup: rbac.authorization.k8s.io
roleRef:
kind: ClusterRole
name: hrcrole
apiGroup: rbac.authorization.k8s.io
我也尝试在命名空间中创建服务帐户,在命名空间中创建集群角色绑定,但我仍然没有。不幸的是,我没有解决这个问题的方法。感谢这里的任何帮助。
解决方案
您正在尝试create
部署:
kubectl auth can-i create deploy --as john -n hr
但是create
集群角色中不允许使用动词:
verbs: ["get", "watch", "list", "delete"]
尝试像这样重新创建集群角色:
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
# "namespace" omitted since ClusterRoles are not namespaced
name: hrcrole
rules:
- apiGroups: ["apps"]
#
# at the HTTP level, the name of the resource for accessing Secret
# objects is "secrets"
resources: ["deployments", "statefulsets", "daemonsets"]
verbs: ["create", "get", "watch", "list", "delete"]
推荐阅读
- php - Laravel 6中的雄辩关系。无法修改/覆盖关系属性
- python-3.x - 如何验证 qtable 小部件不为空
- java - 如何解决“在 HTTP 协议 [HTTP/1.10x0aHost:] 中发现无效字符”?
- javascript - 为什么我的网站在本地完美运行时无法识别 Handlebars?
- json - flutter json解析,能够部分解析
- javascript - 为什么 POST 响应打印未定义?
- javascript - 删除表单中动态创建的元素
- javascript - 尝试 Catch、Async Await 导致生产中的请求超时
- javascript - 表单按钮不断重新加载页面
- python - 如何使用字典设置 Python Pandas 数据框的样式