Skip to content

Instantly share code, notes, and snippets.

@odra
Created July 27, 2021 08:53
Show Gist options
  • Save odra/13db9ff7fc6c5928a2b7cdc2b6b63334 to your computer and use it in GitHub Desktop.
Save odra/13db9ff7fc6c5928a2b7cdc2b6b63334 to your computer and use it in GitHub Desktop.
reads and changes the default namespace for the current kubectl context

Usage

Get Current Default NS

$ kubectl ns
Current default namespace is "koji".

Sets New Default Namespace

$ kubectl ns koji
Context "minikube" modified.
Default namespace switched to "koji".
#!/bin/bash
if [[ "$1" == "" ]]; then
NS=$(kubectl config view --minify --output 'jsonpath={..namespace}')
echo "Current default namespace is \"$NS\"."
exit 0;
fi
kubectl config set-context --current --namespace=$1
echo "Default namespace switched to \"$1\".
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment