即使我是所有者和管理员,也无法在GKE中创建群集角色

问题描述 投票:11回答:4

创建新的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

哪个成功,但在创建集群角色时仍然会遇到相同的错误。

我有什么想法可能做错了吗?

kubernetes google-cloud-platform rbac google-kubernetes-engine
4个回答
9
投票

根据Google Container Engine docs,您必须首先创建一个RoleBinding,它授予您要创建的角色中包含的所有权限。

Get current google identity

$ gcloud info | grep Account

Account: [[email protected]]

Grant cluster-admin to your current identity

$ kubectl create clusterrolebinding myname-cluster-admin-binding --clusterrole=cluster-admin [email protected]

Clusterrolebinding "myname-cluster-admin-binding" created

现在您可以毫无问题地创建ClusterRole。

我在CoreOS FAQ / Troubleshooting找到了答案,请查看更多信息。


3
投票

@ S.Heutmaker的评论让我得到了解决方案。

对我来说,解决方案是使用电子邮件地址上的正确大小创建cluster-admin-binding。检查错误消息或google云控制台IAM中的大小写

$ kubectl create clusterrolebinding myname-cluster-admin-binding --clusterrole=cluster-admin [email protected]

1
投票

这是正确的解决方案。 GCP_USER是否与角色创建错误消息中的[email protected]用户名相同?


0
投票

如果你有正确的套管,尝试添加两个googlemail域变种(即@gmail.com@googlemail.com)。对我来说,gcloud info | grep Account返回<name>@googlemail.com,但我必须创建一个与<name>@gmail.com绑定的集群,以便命令工作。

© www.soinside.com 2019 - 2024. All rights reserved.