I have been using https://github.com/kubernetes/client-go/blob/master/examples/out-of-cluster-client-configuration/main.go#L45 as a guide to create a Kubernetes client in my go code.
However, I am used to using kops (https://github.com/kubernetes/kops) to configure my local kubectl
to point to the cluster I am currently working on. The process I use looks like:
$ export KOPS_STATE_STORE=s3://k8s-state-store
$ kops export kubecfg <name-of-my-cluster>
Where the s3 bucket contains many directories each containing the details needed for kops to configure kubectl
correctly.
I was unable to figure out how to use this same pattern (or the same config files) to configure a kubernetes clientset
in go.
One strategy I am trying is to copy a locally generated ~/.kube/config
that contains only the cluster I am targeting. My code then looks like this:
serveKubeConfigStr := "<Contents of ~/.kube/config>"
config, err := clientcmd.NewClientConfigFromBytes([]byte(serveKubeConfigStr))
if err != nil {
return err
}
clientConfig, err := config.ClientConfig()
if err != nil {
return err
}
clientset, err := kubernetes.NewForConfig(clientConfig)
if err != nil {
return err
}
However, this is not great. I would prefer to be able to specify the URL of the kops configuration.
Is there something big I'm missing in order to make this easier, simpler, and cleaner?