Skip to content

Instantly share code, notes, and snippets.

@scjudd
Last active February 8, 2022 14:22
Show Gist options
  • Save scjudd/e9789e47379726fc6d75d0e7e0e6dc1c to your computer and use it in GitHub Desktop.
Save scjudd/e9789e47379726fc6d75d0e7e0e6dc1c to your computer and use it in GitHub Desktop.
kubectl context and namespace helpers
#!/bin/bash
if [ "$#" -lt 1 ]; then
kubectl config current-context
else
kubectl config use-context $1
fi
#!/bin/bash
if [ "$#" -lt 1 ]; then
context=$(kubectl config current-context)
kubectl config get-contexts --no-headers $context | awk '{print $5}'
else
echo "Setting namespace to $1"
kubectl config set-context --current --namespace $1
fi
@scjudd
Copy link
Author

scjudd commented Feb 8, 2022

These enable you to type kubectl ctx foo to change your context to foo, and kubectl ns bar to set the namespace of the current context to bar. Without any parameters they display the current context and namespace, respectively.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment