Is there an API endpoint to get the kubeconfig file of a cluster from Rancher using its own API?

2.9k Views Asked by At

I'm trying to find a way to get the kubeconfig file using curl command and hit the rancher API. Is there an API endpoint to get that ?

I tried calling these following endpoints but no luck.

https://clusters.bazzinga.com/v3/clusters/c-abcde?action=importYaml
https://clusters.bazzinga.com/v3/clusters/c-abcde?action=generateKubeconfig
1

There are 1 best solutions below

2
Vlad On BEST ANSWER

According to the Rancher docs

Most resources have actions, which do something or change the state of the resource. To use these, send a HTTP POST to the URL in the actions map for the action you want ...

This works for me like a charm:

curl -s -X POST -H "Authorization: Bearer $RANCHER_TOKEN" https://clusters.bazzinga.com/v3/clusters/c-abcde?action=generateKubeconfig | jq -r ".config"