Created
October 21, 2022 10:41
-
-
Save indradhanush/98814b70a8018620acf6a5058ede62ce to your computer and use it in GitHub Desktop.
A bash function to switch namespaces in the current Kubernetes cluster
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
change-ns () { | |
namespace=$1 | |
if [ -z "${namespace}" ] | |
then | |
namespace="default" | |
fi | |
context=$(kubectl config current-context) | |
kubectl config set-context "${context}" --namespace "${namespace}" > /dev/null | |
yellow="\033[1;93m" | |
green="\033[1;92m" | |
reset="\033[0m" | |
echo -e "Namespace set to ${yellow}${namespace}${reset} in context ${green}${context}${reset}." | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment