The Best 3 Tools for Working with Many Kubernetes Contexts

By Pavan Gudiwada, Robusta.dev – Developer Advocate

Working with multiple clusters is always a challenge. It’s too easy to run a command on the wrong cluster. Furthermore, if you switch clusters multiple times a day, it should be fast and convenient. Running kubectl config use-context <context_name> every time you want to switch contexts is not productive.

We will look at 3 tools that will make your life easier. We’ll evaluate them in the following categories.

Speed:
 
       How fast can you switch your Kubernetes context if you have many clusters to choose from? Do you remember the names of all the contexts you use?

Flexibility:
         Does the tool have advanced features like support for multiple config files?

Safety:
         Can you have multiple terminals open, each running its own cluster? Will switching the context in one terminal effect other terminals and increase the chance of errors?

Kubectx

Kubectx is the most popular tool for switching Kubernetes contexts, but it has the fewest features! It displays all the contexts in your Kubeconfig as a selectable list and lets you pick one. That’s it!


Install Kubectx

Kubectx works with all major platforms, Linux, Windows & macOS. It can be installed with native package managers like helm.
You can also install it as a Kubectl plugin using kubectl krew install ctx. More details here.


Limitations

When changing your Kubernetes context, kubectx changes it globally for all terminal sessions!

Kubie

Kubie is an alternative to kubectx. It’s fast, flexible, and leaves your Kubeconfig untouched.

  • Use kubie ctx to switch the Kubernetes context of current shell.
  • kubie exec <context> <namespace> <Kubectl command> lets you run a single kubectl command in a specific context
  • You can manage multiple kubeconfig files and customize Kubie’s behavior by modifying settings in the  ~/.kube/kubie.yaml file.


Install Kubie

Kubie installation packages are available for macOS and Linux, not windows. Instructions here.


Kubeswitch

Kubeswitch has the best features of both Kubectx and Kubie. It is the clear winner and the tool that we’ll be using ourselves in the future.

  • With Hooks (similar to Git Hooks) you can run executables/ inline shell commands at the time of your choosing automatically.
  • You can get lightning-fast search across hundreds of Kubernetes contexts by enabling the search index feature. This indexes all of your contexts across multiple local and remote systems. Note that you must manually refresh the index to prevent outdated results.


Other Features

  • Change history - A list of all the contexts you previously switched to.
  • Context Alias - Give your contexts an alias to help you access quickly.
  • Terminal Isolation - Access multiple clusters from different Terminal windows


Install Kubeswitch

If you are not on MacOS, downloading and installing from source or binary might be a little complicated. But it is definitely worth your time. Detailed instructions here.


kubectx vs kubie vs kubeswitch

Comparison of the three tools


Closing notes

Looks like we’ll be switching to Kubeswitch ourselves! If you work with multiple Kubernetes clusters, share your tips with us on Twitter and LinkedIn.

FYI, we’re building the best UI to see all your Prometheus alerts and clusters in one place. Take a look at Robusta UI.

Never miss a blog post

Create your account to get started

Email us, and we'll provide you with a login link to complete your onboarding from your computer, where Robusta performs at its best.

Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.