Is there a golang sdk equivalent of "gcloud container clusters get-credentials"

5/17/2019

Is there a golang sdk equivalent of: gcloud container clusters get-credentials

I have created a gke cluster using golang sdk google.golang.org/api/container/v1. Now I want to obtain the kubeconfig for the created cluster. Is there way in golang to achieve that?

I have explored the func (r *ProjectsZonesClustersService) Get(projectId string, zone string, clusterId string) *ProjectsZonesClustersGetCall. But this returns the complete cluster configuration not the kubeconfig.

I expect to get the kubeconfig of the gke cluster using golang google container sdk.

-- Yusuf Kanchwala
go
google-cloud-platform
google-kubernetes-engine

1 Answer

5/17/2019

The GKE API does not have a call that outputs a kubeconfig file (or fragment). The specific processing between fetching a full cluster definition and updating the kubeconfig file are implemented in python in the gcloud tooling. It isn't part of the Go SDK so you'd need to implement it yourself.

You can also try using kubectl config set-credentials (see this) and/or see if you can vendor the libraries that implement that function if you want to do it programmatically.

-- Robert Bailey
Source: StackOverflow