In this post I’ll tell you a bit about K9s, which is an open source, command line interface for Kubernetes that makes me feel like a super hero. I’ll tell you what K9s is, why I like it so much, and what the trade-offs are. I hope that to convince you to give it a shot, and that you’ll love it as much as I do.
What is K9s?
- Open Source Cross Platform CLI for Kubernetes
- Intermittently polls cluster resources
- Quickly navigate contexts, namespaces and resources
- Quickly Filtering, sorting, and copying
- Steep, but short learning curve
If you have worked with Kubernetes for very long, then you know how often you have to “kubectl”. It’s a lot, probably a “babillion” times per day. There are clever short-cuts you can take, but ultimately the tool is a thin veneer over the Kubernetes API. There are benefits to working so closely with the API itself, but ultimately it’s a lot of work to do fairly routine tasks.
Think about how Often you “get pods”, “logs”, or “port-forward”. What about those times you need to look up a secret or edit a custom resource you can’t quite remember the name of? Have you ever made your changes only to later realize you altered the wrong cluster or namespace? Oops.
K9s solves these problems by focusing on the user experience, crafting an interface to the Kubernetes API that is convenient for humans. K9s presents you with a resource oriented view that offers filtering, sorting, and context-sensitive actions. It does this via a command-line interface, with a heavy emphasis on short-cuts. The command-line nature and short-cuts are a large part of what makes K9s so great, but they are also the source of it’s learning curve.
Why do I like K9s?
Speed:
- Refreshing in the background
- No more looking up pod names by label or autocomplete (if you’re on bash)
- Swapping namespaces and Contexts
- Multiple instances (no changing of default)
- Saving, Filtering logs
- Sorting
- Easy secrets
Visibility:
- Always know your…
- Namespace
- Context
- Cluster
- Doesn’t change your default context/namespace
Bonus points
- Pulses
- Popeye
- Accidentally learning new things
- Easy to install on remote servers
What can I say? I love how K9s makes me feel. It polls for resources in the background, which makes it fast for me to zip around between screens. This also makes it really easy to filter and sort tabular information. Filtering is done via the “/” key, it supports wildcards, labels and information that isn’t immediately available on the screen (More akin to grepping a “kubectl describe” than a “kubectl get”, if that makes sense). Filtering also works on all views, including logs and yaml.
There are context specific actions available as well. For example you can hit “shift-f” to port-forward on a page with services, deployments or pods. You hit “l” for logs, “s” to shell in, “ctrl-d” to delete and so forth.
If you work in a multi-cluster and/or with multiple namespaces then you will be glad to know that the cluster, context and namespace are visible in the top area. Even better, swapping the context (:context or :ctx) or the namespace (:namespace or :ns) does *not* change your global context. It’s like passing –context and –namespace along with every command. This makes it easy to work with multiple clusters at once, even with multiple instances of K9s.
Everything I described here is fast and simple but it takes sometime to build that muscle memory. There are only a few things you need to remember. I posted a video at the top of this article, but here is the short of it. Once you’ve internalized those keystrokes, the rest will fall into place and you’ll be zooming around like a superhero in no time.
Just remember this:
- ctrl-a (See all the things, including custom resources!)
- : navigates (contexts, namespaces, tools, and resources)
- ? for help
- / filters (works on just about anything)
One more quick thing I want to mention? Ever heard of pulses, popeye, or x-ray? These are all tools that I learned of because I saw them with ctrl-a. I’ve also bumped into other resources (custom or otherwise) that I hadn’t heard of before. K9s made it easy to discover these tools and resources, and I feel like I’m constantly bumping into something new.
What are the trade-offs
- kubectl is ubiquitous
- You can’t script k9s
- Batch operations aren’t fantastic either
- Large clusters can be slow (Drop that poll time down!)
- “Freemium” (There are plans for k9s to offer a paid, premium version in the future)
If you can’t tell by now, I love K9s. I’ve shown it to many people at this point, and I want to mention the common arguments I hear against using it. For the most part they really just boil down to benefits of sticking with kubectl. Of course, there is nothing stopping you from using kubectl at any point but there is something to be said for sticking with one tool…especially when that tool is completely ubiquitous.
Conclusion
As you can see, I’m rather fervent about it because k9s makes me feel like I have super powers. I feel fast, safe, and like I’m getting stronger everyday. I had to spend some time up front getting used to it, but now I feel like I’m flying. I never thought I’d be making such grand statements about a command line interfaceface tool…but here we here. Now hit the links and give it a shot! Feel free to join the slack, or reach out to me if you have any questions!
Links: