How to export kubeconfig file from existing cluster?

Viewed 29576

Is there an easy way to export kubeconfig file from existing cluster so i can use it in CI/CD ?

4 Answers

What kind of cluster is it? A managed(AKS,EKS or GKE etc) one, where is it deployed? Can you ssh in to master node, if yes, please

cat /etc/kubernetes/admin.conf or cat ~/.kube/config

and copy the file, which is the kubeconfig for your cluster.

Other ways to create the kubeconfig, Run the following command

kubectl config view --minify, it will display all the info except for the client ca certificate and client key. The location of those keys depends on how the cluster is setup.

First, locate your kubeconfig file. Generally, it is present at following location: /etc/kubernetes/admin.conf

And then export it by running following command:

export KUBECONFIG=/etc/kubernetes/admin.conf

It is also a good idea to add it in ~/.bashrc file so that you don't have to export it again when the kubeconfig changes.

I have several clusters running on GKE and ssh'ing into the master node didn't work for me, but I was able to run cat ~/.kube/config locally and it gave me everything I needed including the certificate information I needed for my 3rd party application.

Make sure you connect locally so your kubectl is configured correctly,

gcloud container clusters get-credentials

Hopefully, that helps.

Related