Composing Kubectl Commands in Style with Kubed

Tight integration with the command line in my new Emacs package for Kubernetes

Created on [2024-07-31], last updated [2024-07-31]

Last week I announced my new Emacs interface for Kubernetes, Kubed, on the Emacs development mailing list. So far working on Kubed has been a lot of fun, and in this post I want to highlight a feature that I find especially delightful.

First I should mention that Kubed uses kubectl to interact with Kubernetes. This is similar to how Magit uses the git program to interact with, well, Git. One of the design goals for Kubed is to provide the full power of kubectl: if you can do it with kubectl you can do it with Kubed, too. For many common operations, Kubed provides a much nicer experience than what you would get by running kubectl in a terminal, but kubectl is abundant with subcommands and flags and options, and for some use cases the versatility of the command line is irreplaceable.

So rather than hiding the kubectl command line deep under the hood, Kubed embraces and enhances it.

kubed-1.png

The command kubed-kubectl-command lets you invoke a quick kubectl command line whenever you need it. Emacs minibuffer completion is hooked directly to the hidden kubectl subcommand __complete which gives you the same completions you get in the shell. In fact, this __complete subcommand is not unique to kubectl, it’s an artifact of the Golang CLI framework that kubectl uses, Cobra. This framework is very widespread in the Go ecosystem, and since Kubed’s command line completion uses Cobra’s shell-agnostic completion interface, it Just Works with any Cobra program!

kubed-docker.png
kubed-helm.png

Note: these screenshots show my custom minibuffer completions interface, with vanilla Emacs things look slightly different.

You can summon kubed-kubectl-command from the menu-bar “Kubernetes” menu (enable kubed-menu-bar-mode to see that menu first), and if you have the prefix keymap kubed-prefix-map bound to e.g. C-c k, then you can also invoke kubed-kubectl-command by typing C-c k !.

kubed-3.png

But the real magic happens when you call this command from one of the Kubed transient menus. These keyboard-driven menus let you compose complex Kubernetes operations with an intuitive interface, and all Kubed transient menus bind the ! key to kubed-kubectl-command. When you invoke kubed-kubectl-command from a transient menu, it automatically populates your initial command line according to the transient menu you came from and the options you’ve set there.

kubed-4.png
kubed-5.png

That’s pretty cool, I think. In particular it means that you can always start by exploring the Kubed transient menus, and if the exact operation you want to carry out doesn’t have a dedicated Kubed command, then you can hit ! to seamlessly drop to the right kubectl command line.

That’s it for now! If you feel like giving Kubed go, you can grab it from here, or clone it one of the following mirrors: