Skip to content

Instantly share code, notes, and snippets.

@shpwrck
Created March 7, 2022 21:17
Show Gist options
  • Save shpwrck/845722d408884be2c762ee1b47a82e3d to your computer and use it in GitHub Desktop.
Save shpwrck/845722d408884be2c762ee1b47a82e3d to your computer and use it in GitHub Desktop.
Alias to get kubeconfigs from Rancher
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