403"gcloud容器集群get-credentials期间请求的认证范围不足"

sca*_*cai 25 google-cloud-platform google-kubernetes-engine

从GCE的VM中,我做了以下操作

gcloud auth activate-service-account --key-file <blah>
# "blah" is a service account key file (JSON) I generated from the web interface
gcloud config set project <project-name>
gcloud config set compute/zone <zone-name>
gcloud set container/cluster <cluster-name>
Run Code Online (Sandbox Code Playgroud)

然后,当我试图跑

gcloud container clusters get-credentials <cluster-name>
Run Code Online (Sandbox Code Playgroud)

它失败并显示错误消息:

错误消息:"错误:(gcloud.container.clusters.get-credentials)ResponseError:code = 403,message = Request的身份验证范围不足."

VM与GKE集群位于同一网络中.我使用来自GCE外部的计算机的相同服务帐户密钥文件,针对"默认"网络上的GKE集群尝试了同样的事情,并且它成功...

Rob*_*ley 34

要从GCE虚拟机使用Google Kubernetes Engine API,您需要在创建虚拟机时将其添加到VM 平台范围(" https://www.googleapis.com/auth/cloud-platform ").

  • 如果您使用的是命令行,那么您可以执行类似`gcloud compute instances create NAME --scopes = https:// www.googleapis.com/auth/cloud-platform`的操作.如果您使用的是云控制台,则在创建VM时会查找"身份和API访问"部分,并选择"允许对所有Cloud API的完全访问权限". (3认同)
  • 创建集群后是否可以添加云平台范围? (2认同)
  • 现在,您可以在创建后更改范围权限。只需关闭计算机,单击“编辑”,然后转到“作用域”部分。 (2认同)