Authenticating with GKE without Gcloud CLI in Golang
Usually when interacting with GKE, the client is either inside the GKE itself or it has gcloud avilable to help fetch the kubeconfig to auth with GKE. However, sometimes we don’t have the Gcloud CLI available. Today we’ll brifely introduce how to build the config to auth with GKE without the Gcloud CLI
Here are the steps on how to authenticate with GKE without Gcloud CLI in Golang:
- Initialize a GKE cluster client and add the ServiceAccount it needs to impersonate
2. Fetch the cluster metadata e.g. CA/Cluster Endpoint
3. Build a rest.Config with the information fetched and client account information
4. Install the gke-cloud -auth-plugin following https://cloud.google.com/kubernetes-engine/docs/how-to/cluster-access-for-kubectl#install_plugin