-
-
Save InAnimaTe/eeeb4b01467d74c522b94f12ed009889 to your computer and use it in GitHub Desktop.
kubectl context/namespace switcher!
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
function kcc () { | |
usage () { | |
echo -en "Usage: $0 <context> <namespace>\n" | |
} | |
result () { | |
echo -en "-> Context: \e[96m$context\e[0m\n-> Namespace: \e[92m$namespace\n\e[0m" | |
} | |
if [ $# -eq 0 ] ; then | |
## If no options, print the current context/cluster and namespace | |
context="$(kubectl config current-context 2>/dev/null)" | |
namespace="$(kubectl config view -o "jsonpath={.contexts[?(@.name==\"$context\")].context.namespace}")" | |
result | |
elif [ $# -eq 2 ]; then | |
## If options, assume time to set | |
context="$1" | |
namespace="$2" | |
kubectl config use-context "$context" > /dev/null | |
kubectl config set-context "$context" --namespace="$namespace" > /dev/null | |
result | |
else | |
usage | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment