Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
shamhub opened this issue Aug 6, 2022 · 1 comment
Closed

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

shamhub opened this issue Aug 6, 2022 · 1 comment

Comments

@shamhub
Copy link

shamhub commented Aug 6, 2022

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
Copy link
Author

shamhub commented Aug 17, 2022

Resolved

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant