创建新的GKE集群后,创建集群角色失败,并显示以下错误:
Error from server (Forbidden): error when creating "./role.yaml":
clusterroles.rbac.authorization.k8s.io "secret-reader" is forbidden:
attempt to grant extra privileges: [PolicyRule{Resources:["secrets"],
APIGroups:[""], Verbs:["get"]} PolicyRule{Resources:["secrets"],
APIGroups:[""], Verbs:["watch"]} PolicyRule{Resources:["secrets"],
APIGroups:[""], Verbs:["list"]}] user=&{XXX@gmail.com
[system:authenticated] map[authenticator:[GKE]]} ownerrules= .
[PolicyRule{Resources:["selfsubjectaccessreviews"
"selfsubjectrulesreviews"], APIGroups:["authorization.k8s.io"], Verbs:
["create"]} PolicyRule{NonResourceURLs:["/api" "/api/*" "/apis"
"/apis/*" "/healthz" "/swagger-2.0.0.pb-v1" "/swagger.json"
"/swaggerapi" "/swaggerapi/*" "/version"], Verbs:["get"]}]
ruleResolutionErrors=[]
我的帐户在IAM中具有以下权限:
Kubernetes Engine Admin Kubernetes Engine Cluster Admin Owner
这是我 role.yaml
(来自Kubernetes docs):
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: secret-reader
rules:
- apiGroups: [""]
resources: ["secrets"]
verbs: ["get", "watch", "list"]
根据RBAC docs of GCloud,我需要
在尝试创建其他Role或ClusterRole权限之前,创建一个RoleBinding,为您的Google身份提供群集管理员角色 .
所以我试过this:
export GCP_USER=$(gcloud config get-value account | head -n 1)
kubectl create clusterrolebinding cluster-admin-binding
--clusterrole=cluster-admin --user=$GCP_USER
哪个成功,但在创建集群角色时仍然会遇到相同的错误 .
我有什么想法可能做错了吗?
2 回答
根据Google Container Engine docs,您必须首先创建一个RoleBinding,它授予您要创建的角色中包含的所有权限 .
获取当前的Google身份
将cluster-admin授予您当前的身份
现在您可以毫无问题地创建ClusterRole .
我在CoreOS FAQ / Troubleshooting找到了答案,请查看更多信息 .
这是正确的解决方案 . GCP_USER是否与角色创建错误消息中的
XXX@gmail.com
用户名相同?