无法连接到Google Container Engine

sku*_*erk 5 google-cloud-platform google-kubernetes-engine

我已经把gcloud更新到了最新版本(159.0.0)

我创建了一个Google Container Engine节点,然后按照提示中的说明进行操作。

gcloud container clusters get-credentials prod --zone us-west1-b --project myproject

Fetching cluster endpoint and auth data.
kubeconfig entry generated for prod

kubectl proxy
Unable to connect to the server: error executing access token command 
"/Users/me/Code/google-cloud-sdk/bin/gcloud ": exit status 
Run Code Online (Sandbox Code Playgroud)

知道为什么它无法连接吗?

小智 5

您可以尝试运行以查看配置是否正确生成:

kubectl config view 
Run Code Online (Sandbox Code Playgroud)

我在尝试在刚刚在 Google Cloud Platform 上创建的新 Kubernetes 集群上运行 kubectl 命令时遇到了类似的问题。

我的情况的解决方案是激活Google Application Default Credentials

您可以在下面找到有关如何激活它的链接。

基本上,您需要使用GOOGLE_APPLICATION_CREDENTIALS -> c:\...\..\..Credentials.json从 Google Cloud https://developers.google.com/identity/protocols/application-default-credentials导出的 GCP 凭据将环境变量设置为 .json 的路径

我在 kuberenetes github 问题上找到了这个解决方案:https : //github.com/kubernetes/kubernetes/issues/30617

PS:确保您还设置了以下环境变量: %HOME% 到 %USERPROFILE% %KUBECONFIG% 到 %USERPROFILE%


jef*_*fml 5

看起来GKE的默认auth插件在Windows上可能有问题。kubectl尝试运行gcloud以获得令牌以对您的集群进行身份验证。如果运行kubectl config view,则可以看到它尝试运行的命令,然后自己运行以查看是否/为什么失败。

正如Alexandru所说,一种解决方法是使用Google Application Default Credentials。实际上,gcloud容器内置了对此功能的支持,您可以通过设置属性来进行切换:

gcloud config set container/use_application_default_credentials true

或设置环境变量

%CLOUDSDK_CONTAINER_USE_APPLICATION_DEFAULT_CREDENTIALS%true