Working in GCP with several kubernetes clusters, I would like to automatically get cluster credentials when switching gcloud configurations.
I have created several configurations for gcloud with gcloud config configurations create [config-name]
and I have set what I need, specifically gcloud config set container/cluster [cluster-name]
.
When I switch configurations with gcloud config configurations activate [config-name]
, everything goes ok, except I do not get the credentials for the cluster I have configured for that configuration. Instead I need to run gcloud container clusters get-credentials [cluster-name]
.
Is there any way to automatically get credentials for a cluster when activating a gcloud configuration?
I think not.
gcloud
and kubectl
are distinct tools and each maintains its own configuration.
gcloud container custers get-credentials
is a bridging helper that configures kubectl
configuration (conventionally located in ~/.kube/config
file) with a gcloud
auth helper to facilitate accessing Kubernetes Engine clusters. But, otherwise the 2 tools are unrelated.
Have a look at this post I wrote that covers using different configurations with kubectl
. It's not exactly what you want but I hope it will be useful:
https://medium.com/google-cloud/context-light-gcloud-and-kubectl-89185d38ce82