I touched this way or another on the Kubernetes topic—first, it was the part of this series in the Contexts post where I wrote about kctx which I use almost daily; second, it was a dedicated post about Kubernetes specifically, discussing what I like and dislike about it etc. In one of these posts I even smuggled a screenshot of what I'm going to write about today.
As I mentioned in the past, I really liked databricks/click:
For a very long time, click was my only way of coping with all things Kubernetes. It was still very confusing with all the contexts, namespaces, pods, and containers, but at the very least, I was able to reason about some stuff that was running there.
At some point, I took the advice of a good friend and embraced all things kubectl. However, once I started using it, I found all the typing to be too tedious for my liking, so I decided to script my way out of it. That's how koc came to be:

It's not much, only 88 lines of Bash, but it is absolutely indispensable for me whenever I need to deal with anything related to Kubernetes. The main driver, to nobody's surprise, is the insanely capable junegunn/fzf.
I had to figure out some of the flow; for example, the escape key always exits the entire app. The initial screen looks like this:

Cool? Cool. But how do you get back to it once the choice has already been made? As mentioned, escape exists the entire app, so I went with ^-c—far from ideal, but works for me. If I'm in the pod overview and I need to check deployment for it, I just smash that ^-c, and off I go.
I tried to keep hard dependencies to the bare minimum:
- junegunn/fzf (I still didn't settle on specific version so it's latest for now, sorry)
- kubernetes/kubectl (whatever works for you, I guess)
There are also two soft dependencies:
- sharkdp/bat—used to pretty print info in describe and previews (fallbacks to
less) - stern/stern—used to pretty print logs (fallbacks to
kubectl logs)
I didn't want to depend on my own shit, so koc comes with built-in "mini" kctx version to figure out which context to use on the first run.
OK, so what can you do with it? First, you select context, unless one was already set. Then you pick resource you are after. And then, you've got the following options:
- You can scroll up and down with the arrow keys or
^-jand^-k(or^-nand^-p) returnto have a full screen description of the selected resource (nice and pretty ifbatis available)^-lto view the logs of the selected resources (nice and pretty ifsternis available)^-sto enter the container of the selected resource (it's usingkubectl exec -itunderneath and will pick the first container if there's more than one—there's currently no way to pick any other)^-rto refresh the view (there's no auto-refresh) and keeping the query (by default it's^default)^-qto refresh the view and clean the query^-xto delete the selected resource^-/to toggle the preview of the selected resource. Initially it's horizontal, doing it second time switches the view to vertical; third time closes the preview. When preview is active, switching resources is dynamically updated so it's very easy to quickly view more details about each resource. Scrolling in the view is also possible via^-uto go up and^-dto go down
As was said already, ^-c is used to get back to the initial resources picker. I'm really happy with the result and I find it absolutely amazing how much can be done with software like fzf 🤯
There are some things I'd love to see improved somewhere down the line, although they've never become problematic enough for me to action any of them:
- I would love to have the ability to narrow down the view to only specific namespace without any external app like
kubens(right now all namespaces are queried and only then filtered out) - I'm not that fond of using
^-cfor switching back to the resources picker - I remember
clickhad the ability to show all the containers within a pod, and also possibility to log into any of them by picking, but I was unable to thus far to replicate this functionality - Would be great to have a way to specify different than
^defaultinitial query (via argument or something) - Better resource picker, that isn't simply static list to iterate over would also be nice
Overall, this is my way of dealing with Kubernetes. What I like the most is that it's pretty much very lightweight, powerful and fast wrapper on top of kubectl. It's not an API, it's not a different software, these kubectl commands are powering everything I need in order to be productive there. It's fast, convenient and it does all this while staying very lean. You can find the script here.
Demo
Wrap up
I spawned up a repository on GitHub where I'm going to gradually fill in with some pretty terrible shell scripting. I'll do my best to cover most of these scripts on this blog, so there will probably be more parts to this series. You can find the previous one, where I covered my obsession with contexts, here:
In case you've got any feedback, feel free to reach out on Mastodon!
Discussion