Skip to content

Instantly share code, notes, and snippets.

@indradhanush
Created October 21, 2022 10:41
Show Gist options
  • Save indradhanush/98814b70a8018620acf6a5058ede62ce to your computer and use it in GitHub Desktop.
Save indradhanush/98814b70a8018620acf6a5058ede62ce to your computer and use it in GitHub Desktop.
A bash function to switch namespaces in the current Kubernetes cluster
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