Last active
August 7, 2023 11:01
-
-
Save ngraf/35f0fc30f7118e97bda69ae89fa3759c to your computer and use it in GitHub Desktop.
A script to switch kubectl context easily. For example by creating this file in "/usr/local/bin/context" you can switch context easily by executing "context" in console on any place.
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
#!/usr/bin/env bash | |
CONTEXTS=`kubectl config get-contexts -o name | sort` | |
# Save current IFS | |
SAVEIFS=$IFS | |
# Change IFS to new line. | |
IFS=$'\n' | |
CONTEXTS=($CONTEXTS) | |
# Restore IFS | |
IFS=$SAVEIFS | |
echo -e "\nselect context: (current context: `kubectl config current-context`)\n" | |
select CONTEXT in "${CONTEXTS[@]}" | |
do | |
echo "" | |
kubectl config use-context $CONTEXT | |
break; | |
done; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment