Skip to content

Instantly share code, notes, and snippets.

@leosunmo
Last active March 16, 2017 02:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leosunmo/ef451224314259c1d90f38814cd5441f to your computer and use it in GitHub Desktop.
Save leosunmo/ef451224314259c1d90f38814cd5441f to your computer and use it in GitHub Desktop.
Example of bashrc/zshrc kubectl function for multi-namespace/multi-region
# one function per cluster/region
function kus() {
case $1 in
# set namespace based on first arg
red)
kubectl --context=kube-prod-us --namespace=red ${@:2}
;;
green)
kubectl --context=kube-prod-us --namespace=green ${@:2}
;;
blue)
kubectl --context=kube-prod-us --namespace=blue ${@:2}
;;
#If no namespace is specified, pass on args to just the context
*)
kubectl --context=kube-prod-us $@
esac
}
function keu() {
case $1 in
red)
kubectl --context=kube-prod-eu --namespace=red ${@:2}
;;
green)
kubectl --context=kube-prod-eu --namespace=green ${@:2}
;;
blue)
kubectl --context=kube-prod-eu --namespace=blue ${@:2}
;;
*)
kubectl --context=kube-prod-eu $@
esac
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment