If you have worked with Kubernetes, you may have had to work with kubectl to run commands in your cluster. While it’s a powerful tool, I often go back to the documentation for commands that I use less often while troubleshooting.

Don’t you always forget the config while trying to see the current context? I had made an article with common kubectl commands to help me remember them. Aliases do help like alias k="kubectl", you could go further, but it’s not very verbose or mnemonic for me.

So here the’s the solution for a terminal-based UI for Kubernetes: K9s!

K9s

K9s is an open source project that behaves like an enhanced vim for Kubernetes. It makes it easier to navigate your cluster, manage and edit resources with vim like commands and a nice interface in the terminal.

When you type k9s once installed in the terminal it should show:

k9s.png

That’s a little screenshot from the official repository of what it looks like. It does support customization, but that’s not really why I use it.

Installation

On MacOS, I am using zsh as my shell in an iTerm2 terminal, not that it should influence the installation, but it might look slightly different on other systems. You can install K9s via Homebrew using:

brew install derailed/k9s/k9s

Or follow the official installation guide for other platforms. The process is for once pretty straightforward, and you can start using it right away. (You do need a K8s cluster running, but that’s another story).

Shortcut

I am using Version: v0.31.9 and I have compiled a list of useful commands or shortcuts to best use k9s. You can find more information in the documentation as well. The use of : to enter the command made me remember vim commands, so it was easier to get into it.

  • Quit K9s:
    • : + q as in vim then enter to send the command and quit.
    • ctrl + c also works.
  • Find a resource:
    • : then type the resource type (deployment, services but also namespace or context)
    • It auto-populates and lets you dive in with enter in it, which can be useful for exploring the cluster.
    • ESC to exit the search or go back to the previous “page”
  • Multi selection:
    • space to select multiple resources
  • Show logs:
    • l to show logs of the selected pod, you can also use this command on a deployment to see all the logs of the deployment’s pods.
  • Search in the screen (for logs but even pods as well):
    • / then type the search term
    • ESC to exit the search and browse through the search results
    • Useful when you want to ctrl + d to delete multiple pods at once, for example.
  • Enter the pod’s shell:
    • s to open a shell in the selected pod/deployment
    • Once in the shell type exit to exit it.
  • Edit the manifest of a resource:
    • e to edit the manifest of the selected resource
    • It opens a vim editor, so you will need to use :wq to save and quit or :q! to quit without saving the changes.

With these commands you should be able to handle most of your day-to-day tasks with k9s without being a pro kubectl exper user. If I missed a key feature, or you have a killer command, let me know in the comments!

Conclusion

K9s is a neat tool to manage your Kubernetes cluster from the terminal. I like the terminal-based UI which gives me the same type of output as the command without having to pass a -f flag to avoid continuously typing get commands.

Give it a try or let me know in the comment what’s your preferred tool to deal with Kubernetes! ⎈