Reputation: 1231
Is there an easy way to export kubeconfig file from existing cluster so i can use it in CI/CD ?
Upvotes: 20
Views: 114633
Reputation: 1711
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. kubectl config view --raw
will show all the configuration (including certificates).
Upvotes: 27
Reputation: 2685
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.
Upvotes: 14
Reputation: 206
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.
Upvotes: 2
Reputation: 1081
You can use gcloud to generate a kubeconfig entry, given that you have at least clusterViewer IAM role:
gcloud container clusters get-credentials cluster-name
For reference:
Upvotes: 7