Skip to content
Advertisement

Authentication using python Kubernetes api in GCP is not working

I would like to be able to access GKE (kubernetes) cluster in GCP from python kubernetes client. I cant authenticate and connect to my cluster and i dont find the reason. Here is what i tried so far.

JavaScript

Advertisement

Answer

I’d like to get the configuration working I have it work where, the code is running off cluster and it produces the kubectl config file for itself. (see update at end)

Original

The first solution assumes (!) you’ve the cluster configured in your local (~/.kube/config and probably adjusted by KUBE_CONFIG) config.

JavaScript

NOTE

  1. Assumes you’ve run gcloud containers clusters get-credentials to set the ~/.kube/config file for the current cluster (and has a current-context set.
  2. Uses your user credentials in the ~/.kube/config file so no additional credentials are needed.

Update

Okay, I have it working. Here’s the code that will generate a kubectl config and connect to the cluster. This code uses Application Default Credentials to provide a Service Account key to the code (usually export GOOGLE_APPLICATION_CREDENTIALS=/path/to/key.json)

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement