Created
October 4, 2022 19:20
-
-
Save steven-terrana/819981abdb6b7a251f46cfda8442ce20 to your computer and use it in GitHub Desktop.
grab all available kubeconfigs from the rancher management console and consolidate
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
#!/bin/bash | |
# this script queries the rancher management console defined via | |
# auth.env to fetch all of the currently available kubeconfig files | |
# | |
# those kubeconfig files are then consolidated into a single kubeconfig | |
# in the default location | |
# | |
# after this script is run - you can use kctx to easily switch between | |
# available clusters | |
set -e | |
source ./auth.env | |
rancher login $RANCHER_MGMT_URL -t $RANCHER_MGMT_TOKEN --context $RANCHER_MGMT_CONTEXT | |
mkdir -p .kube | |
for cluster in $(rancher cluster ls --format '{{.Cluster.ID}}'); do | |
rancher cluster kf $cluster > .kube/$cluster.kubeconfig | |
done | |
KUBECONFIG="$KUBECONFIG:$(find .kube -type f | tr '\n' :)" kubectl config view --flatten > ~/.kube/config | |
rm -rf .kube |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment