client-go icon indicating copy to clipboard operation
client-go copied to clipboard

Go package to generate kubeconfig and store in .kube/config

Open shamhub opened this issue 3 years ago • 0 comments

To use kubectl with merged config,

below two commands can be used:

KUBECONFIG=~/.kube/config:/path/to/another/config.yml kubectl config view --flatten > ~/.kube/config-new.yaml

and then

cp ~/.kube/config-new.yaml ~/.kube/config


~/.kube/config will have merged config after running above two commands


In our case(to talk to kubernetes api-server), instead of kubectl, we are planning for a GoLang tool that uses client-go library.

GoLang tool maintains kubeconfig retrieved from MongoDB(every 10 minutes) and stored in Go slice of structs(shown below):

[
   {
      "name" : "cluster-1-in-gcp",
      "kubernetes-version": "1.16",
      "server": "https://192.168.10.190:6443",
      "user": "kubernetes-admin-1",
      "client-certificate": "sadfhdsjfkhsdjfklhsdjfkassdfsd",
      "client-key": "sahgjkshfgjkdf"      
   },
   {
      "name" : "cluster-1-in-aws",
      "kubernetes-version": "1.17",
      "server": "https://192.168.11.191:6443",
      "user": "kubernetes-admin-2",
      "client-certificate": "ssssshdsjfkhsdjfklhsdjfkassdfsd",
      "client-key": "pppppsahgjkshfgjkdf"
   },
   {
      "name" : "cluster-1-in-aks",
      "kubernetes-version": "1.18",
      "server": "https://192.168.11.192:6443",
      "user": "kubernetes-admin-3",
      "client-certificate": "oooossssshdsjfkhsdjfklhsdjfkassdfsd",
      "client-key": "tttttpppppsahgjkshfgjkdf"      
   },
]

client-certificate & client-key are PEM format certificates(stored as string)


Seeking a Go package to merge this kubeConfig(Go slice of structs) to ~/.kube/config?

Does cliendcmd package of client-go library support this merge functionality?

shamhub avatar Aug 06 '22 14:08 shamhub