API to download all kubeconfig

I am trying to download kubeconfig for all the downstream clusters as we do from the UI.

 curl -s -k -X 'POST' \
     -H "Authorization: Bearer $RANCHER_TOKEN" \
     $RANCHER_URL/v3/clusters/$CLUSTER_ID?action=generateKubeconfig | jq -r ".config" > $CLUSTER_NAME.kubeconfig

This is looping over all the clusters id’s and getting the config, what’s the best way to get all clusters config as one single config file?

1 Like

I just wanted to mention the way I ended up achieving this. After generating kubeconfigs for all the clusters, merge them down to a single kubeconfig using the below command,

export KUBECONFIG=$(ls  *.kubeconfig|tr '\n' ':')
echo "Merging all kubeconfig to a single file"
kubectl config view --merge --flatten >all_merged.config

Thanks for your solution, I was looking for the same thing. One question, since the endpoint you’re calling seems undocumented, is there any way to pass a token expiration? I’d like to have short lived tokens (max 1h) since I’m using it into a script.