从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>
然后,当我试图跑
gcloud container clusters get-credentials <cluster-name>
它失败并显示错误消息:
错误消息:“错误:(gcloud.container.clusters.get-credentials)ResponseError:code = 403,message = Request的身份验证范围不足。”
VM与GKE集群位于同一网络中。我使用来自GCE外部的计算机的相同服务帐户密钥文件,针对“默认”网络上的GKE集群尝试了同样的事情,并且它成功...
要从GCE虚拟机使用Google Kubernetes Engine API,您需要在创建虚拟机时将其添加到VM平台范围(“https://www.googleapis.com/auth/cloud-platform”)。
如果您在GCP中使用来自VM的Google Kubernetes Engine API。首先需要在vm级别https://www.googleapis.com/auth/projecthosting,cloud-platform添加所需的范围。这也可以通过GCP控制台完成。停止VM实例,然后转到编辑选项,最后您将找到Cloud API访问范围。