Created
March 7, 2022 21:17
-
-
Save shpwrck/845722d408884be2c762ee1b47a82e3d to your computer and use it in GitHub Desktop.
Alias to get kubeconfigs from Rancher
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export RANCHER_SERVER_URL=<< insert server url here >> | |
export RANCHER_ACCESS_KEY=<< insert access key here >> | |
export RANCHER_SECRET_KEY=<< insert secret key here >> | |
export RANCHER_LOCAL_CONTEXT=<< insert local cluster context here >> | |
function get-kubeconfigs () { | |
# Authenticate to Rancher Server | |
rancher login $RANCHER_SERVER_URL --token $RANCHER_ACCESS_KEY:$RANCHER_SECRET_KEY --context $RANCHER_LOCAL_CONTEXT | |
# Delete previous configs (only if Rancher is your primary Kubernetes interface) | |
rm -rf ~/.kube/* | |
rancher clusters ls --format '{{.Cluster.ID}}' | xargs -I "{}" -n 1 bash -c "konfig import --save <(rancher clusters kubeconfig {})" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment