创建新的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=&{[email protected]
[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引擎集群管理员
所有者
这是我的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
哪个成功,但在创建集群角色时仍然会遇到相同的错误。
我有什么想法可能做错了吗?
根据Google Container Engine docs,您必须首先创建一个RoleBinding,它授予您要创建的角色中包含的所有权限。
$ gcloud info | grep Account
Account: [[email protected]]
$ kubectl create clusterrolebinding myname-cluster-admin-binding --clusterrole=cluster-admin [email protected]
Clusterrolebinding "myname-cluster-admin-binding" created
现在您可以毫无问题地创建ClusterRole。
我在CoreOS FAQ / Troubleshooting找到了答案,请查看更多信息。
@ S.Heutmaker的评论让我得到了解决方案。
对我来说,解决方案是使用电子邮件地址上的正确大小创建cluster-admin-binding。检查错误消息或google云控制台IAM中的大小写
$ kubectl create clusterrolebinding myname-cluster-admin-binding --clusterrole=cluster-admin [email protected]
这是正确的解决方案。 GCP_USER是否与角色创建错误消息中的[email protected]
用户名相同?
如果你有正确的套管,尝试添加两个googlemail域变种(即@gmail.com
和@googlemail.com
)。对我来说,gcloud info | grep Account
返回<name>@googlemail.com
,但我必须创建一个与<name>@gmail.com
绑定的集群,以便命令工作。