3

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
Gautham
  • 33
  • 1
  • 3

1 Answers1

6

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"
Vlad
  • 182
  • 1
  • 7
  • `action=generateKubeconfig` Does it generate a new Kubeconfig ? My objective is not to create a new kubeconfig. I would like to get the existing kubeconfig. @Vlad – Gautham May 18 '22 at 02:12
  • @Gautham I ran it like 5 times, and every time it produced the same config :) Token used in config is, so-called, Kubeconfig token owned by user whom makes request – Vlad May 19 '22 at 14:59