Eoin Molloy
Eoin Molloy

Reputation: 173

Why cant gke-gcloud-auth-plugin retrieve my credentials?

I am trying to connect to my GKE cluster via Kubectl on Windows 11 but am having problems with the gke-gcloud-auth-plugin.

I have followed the instructions in this article https://cloud.google.com/blog/products/containers-kubernetes/kubectl-auth-changes-in-gke but to no success.

Whenever I try to run a command to view resources in kubectl (kubectl get pods -n NAMESPACE) I get this error:

F0814 16:43:55.031825   15116 cred.go:145] print credential failed with error: Failed to retrieve access token:: error parsing gcloud output: invalid character '\x1b' looking for beginning of value
Unable to connect to the server: getting credentials: exec: executable gke-gcloud-auth-plugin.exe failed with exit code 1 

I installed the gke-gcloud-auth-plugin using gcloud components install gke-gcloud-auth-plugin and validated the installation with gcloud components list:

$ gcloud components list

Your current Google Cloud CLI version is: 442.0.0
The latest available version is: 442.0.0

+----------------------------------------------------------------------------------------------------------------+
|                                                   Components                                                   |
+---------------+------------------------------------------------------+------------------------------+----------+
|     Status    |                         Name                         |              ID              |   Size   |
+---------------+------------------------------------------------------+------------------------------+----------+
| Not Installed | App Engine Go Extensions                             | app-engine-go                |  4.6 MiB |
| Not Installed | Appctl                                               | appctl                       | 18.7 MiB |
| Not Installed | Artifact Registry Go Module Package Helper           | package-go-module            |  < 1 MiB |
| Not Installed | Cloud Bigtable Command Line Tool                     | cbt                          | 11.4 MiB |
| Not Installed | Cloud Bigtable Emulator                              | bigtable                     |  7.0 MiB |
| Not Installed | Cloud Datastore Emulator                             | cloud-datastore-emulator     | 36.2 MiB |
| Not Installed | Cloud Firestore Emulator                             | cloud-firestore-emulator     | 42.5 MiB |
| Not Installed | Cloud Pub/Sub Emulator                               | pubsub-emulator              | 61.2 MiB |
| Not Installed | Cloud Run Proxy                                      | cloud-run-proxy              | 12.0 MiB |
| Not Installed | Cloud SQL Proxy                                      | cloud_sql_proxy              |  7.4 MiB |
| Not Installed | Google Container Registry's Docker credential helper | docker-credential-gcr        |  1.8 MiB |
| Not Installed | Log Streaming                                        | log-streaming                | 12.4 MiB |
| Not Installed | Minikube                                             | minikube                     | 34.5 MiB |
| Not Installed | Skaffold                                             | skaffold                     | 22.8 MiB |
| Not Installed | Terraform Tools                                      | terraform-tools              | 66.2 MiB |
| Not Installed | anthos-auth                                          | anthos-auth                  | 20.5 MiB |
| Not Installed | config-connector                                     | config-connector             | 56.9 MiB |
| Not Installed | enterprise-certificate-proxy                         | enterprise-certificate-proxy |  6.5 MiB |
| Not Installed | gcloud Alpha Commands                                | alpha                        |  < 1 MiB |
| Not Installed | gcloud Beta Commands                                 | beta                         |  < 1 MiB |
| Not Installed | gcloud app Java Extensions                           | app-engine-java              | 64.9 MiB |
| Not Installed | gcloud app PHP Extensions                            | app-engine-php               | 19.1 MiB |
| Not Installed | gcloud app Python Extensions                         | app-engine-python            |  8.5 MiB |
| Not Installed | gcloud app Python Extensions (Extra Libraries)       | app-engine-python-extras     | 27.3 MiB |
| Not Installed | kubectl                                              | kubectl                      |  < 1 MiB |
| Not Installed | kubectl-oidc                                         | kubectl-oidc                 | 20.5 MiB |
| Not Installed | pkg                                                  | pkg                          |          |
| Installed     | BigQuery Command Line Tool                           | bq                           |  1.6 MiB |
| Installed     | Cloud Storage Command Line Tool                      | gsutil                       | 11.3 MiB |
| Installed     | Google Cloud CLI Core Libraries                      | core                         | 21.4 MiB |
| Installed     | Google Cloud CRC32C Hash Tool                        | gcloud-crc32c                |  1.3 MiB |
| Installed     | gke-gcloud-auth-plugin                               | gke-gcloud-auth-plugin       |  8.0 MiB |
+---------------+------------------------------------------------------+------------------------------+----------+
To install or remove components at your current SDK version [442.0.0], run:
  $ gcloud components install COMPONENT_ID
  $ gcloud components remove COMPONENT_ID

To update your SDK installation to the latest version [442.0.0], run:
  $ gcloud components update

After this, I ran this command to get the cluster credenentials:

gcloud container clusters get-credentials CLUSTER_NAME --zone ZONE_NAME

Which generated this in my kubeconfig:

- name: gke_MY_PROJECT_ID_MY_REGION_MY_CLUSTER_NAME
  user:
    exec:
      apiVersion: client.authentication.k8s.io/v1beta1
      command: gke-gcloud-auth-plugin.exe
      installHint: Install gke-gcloud-auth-plugin for use with kubectl by following
        https://cloud.google.com/blog/products/containers-kubernetes/kubectl-auth-changes-in-gke
      provideClusterInfo: true

I have also set the system environment variable USE_GKE_CLOUD_AUTH_PLUGIN=TRUE. I have reinstalled kubectl and gcloud several times. Here the versions of kubectl that I am using:

$ kubectl version
F0814 16:59:41.789555   37312 cred.go:145] print credential failed with error: Failed to retrieve access token:: error parsing gcloud output: invalid character '\x1b' looking for beginning of value
WARNING: This version information is deprecated and will be replaced with the output from kubectl version --short.  Use --output=yaml|json to get the full version.
Client Version: version.Info{Major:"1", Minor:"27", GitVersion:"v1.27.4", GitCommit:"fa3d7990104d7c1f16943a67f11b154b71f6a132", GitTreeState:"clean", BuildDate:"2023-07-19T12:20:54Z", GoVersion:"go1.20.6", Compiler:"gc", Platform:"windows/amd64"}
Kustomize Version: v5.0.1
Unable to connect to the server: getting credentials: exec: executable gke-gcloud-auth-plugin.exe failed with exit code 1

My cluster on the GCP console is running 1.24.14-gke.1200

Upvotes: 1

Views: 5840

Answers (1)

kalyani chaudhari
kalyani chaudhari

Reputation: 7849

Below steps worked for me:

  1. Add in your .zshrc or .bashrc : export USE_GKE_GCLOUD_AUTH_PLUGIN=False
  2. source .zshrc or .bashrc
  3. gcloud container clusters get-credentials {{your cluster}} --zone={{your zone}}

Upvotes: 0

Related Questions