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
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"
EDIT 2024:
As pointed out by @Floren, as per Racher v2.8+ while generating kubeConfig, by default, the new token will be created with 30 days expiration!
To change this, one need to change kubeconfig-default-token-ttl-minutes
in Rancher's Global Settings, You can find more on this in official docs here.