Last active
February 8, 2022 14:22
-
-
Save scjudd/e9789e47379726fc6d75d0e7e0e6dc1c to your computer and use it in GitHub Desktop.
kubectl context and namespace helpers
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
#!/bin/bash | |
if [ "$#" -lt 1 ]; then | |
kubectl config current-context | |
else | |
kubectl config use-context $1 | |
fi |
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
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
These enable you to type
kubectl ctx foo
to change your context tofoo
, andkubectl ns bar
to set the namespace of the current context tobar
. Without any parameters they display the current context and namespace, respectively.