Kubernetes Shortcuts & Helpers

If you work in CLI often enough you know how helpful it is to have shortcuts to both save time and key strokes. kubectx is a utility to manage and quickly switch between kubectl contexts.

USAGE:
  kubectx                   : list the contexts
  kubectx <NAME>            : switch to context <NAME>
  kubectx -                 : switch to the previous context
  kubectx -c, --current     : show the current context name
  kubectx <NEW_NAME>=<NAME> : rename context <NAME> to <NEW_NAME>
  kubectx <NEW_NAME>=.      : rename current-context to <NEW_NAME>
  kubectx -d <NAME>         : delete context <NAME> ('.' for current-context)
                              (this command won't delete the user/cluster entry
                              that is used by the context)
  kubectx -u, --unset       : unset the current context

kubens is a utility to manage and quickly switch between Kubernetes namespaces.

USAGE:
  kubens                    : list the namespaces
  kubens <NAME>             : change the active namespace
  kubens -                  : switch to the previous namespace
  kubens -c, --current      : show the current namespace

You can install both with Homebrew

brew install kubectx

If you use ohmyzsh the kubectl plugin adds a ton of aliases to allow you to type less and move faster.

Lastly kube-ps1 is a useful script that displays the current Kubernetes context and namespace on your Bash/Zah prompt strings. Install via Homebrew:

$ brew update
$ brew install kube-ps1