Unable to connect to Google Container Engine

6/20/2017

I've updated gcloud to the latest version (159.0.0)

I created a Google Container Engine node, and then followed the instructions in the prompt.

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 

Any idea why is it not able to connect?

-- skunkwerk
google-cloud-platform
google-kubernetes-engine

3 Answers

5/16/2020

Using GKE, update the credentials from the "Kubernetes Engine/Cluster" management worked for me.

The cluster line provides "Connect" button that copy the credentials commands into console. And this refresh the used token. And then kubectl works again. Why my token expired? well, i suppose GCP token are not eternal.

So, the button plays the same command automatically that : gcloud container clusters get-credentials your-cluster ...

Bruno

-- bruno777
Source: StackOverflow

6/20/2017

You can try to run to see if the config was generated correctly:

kubectl config view 

I had a similar issue when trying to run kubectl commands on a new Kubernetes cluster just created on Google Cloud Platform.

The solution for my case was to activate Google Application Default Credentials.

You can find a link below on how to activate it.

Basically, you need to set an environmental variable to the path of the .json with the credentials from GCP GOOGLE_APPLICATION_CREDENTIALS -> c:\...\..\..Credentials.json exported from Google Cloud https://developers.google.com/identity/protocols/application-default-credentials

I found this solution on a kuberenetes github issue: https://github.com/kubernetes/kubernetes/issues/30617

PS: make sure you have also set the environmental variables for: %HOME% to %USERPROFILE% %KUBECONFIG% to %USERPROFILE%

-- Alexandru Balan
Source: StackOverflow

6/20/2017

It looks like the default auth plugin for GKE might be buggy on windows. kubectl is trying to run gcloud to get a token to authenticate to your cluster. If you run kubectl config view you can see the command it tried to run, and run it yourself to see if/why it fails.

As Alexandru said, a workaround is to use Google Application Default Credentials. Actually, gcloud container has built in support for doing this, which you can toggle by setting a property:

gcloud config set container/use_application_default_credentials true

or set environment variable

%CLOUDSDK_CONTAINER_USE_APPLICATION_DEFAULT_CREDENTIALS% to true.

-- jeffml
Source: StackOverflow