↓Skip to main content

k9s hotkeys are cool

·3 mins

The cli tool k9s has something of a cult following behind it. A terminal user interface (TUI) that allows a given operator the ability to quickly interface with their Kubernetes (K8s) cluster. More importantly you don’t need to remember every last kubectl command ever. Over time you’d wish there was some way to cut to your own helpful commands and the hotkeys function allows this! Not only can you make your own hotkey, the built-in help system will automatically display them. I had a rough start with correct file paths with this so I figured I’d share what I learned.

My goal is to quickly view what resources exist in a namespace. We’re going to bind X-Ray view of deployments to a hotkey we can call at any time.

Setup #

  • Running on a 2020 Mac Book Pro w/ MacOS 15.3.2
  • k9s installed via homebrew

Info #

Before you begin, you may want to read the README.md of the k9s project where it’ll detail k9s info.

➜ k9s info
 ____  __ ________
|    |/  /   __   \______
|       /\____    /  ___/
|    \   \  /    /\___  \
|____|\__ \/____//____  /
         \/           \/

Version:           0.40.10
Config:            /Users/bobby/Library/Application Support/k9s/config.yaml
Custom Views:      /Users/bobby/Library/Application Support/k9s/views.yaml
Plugins:           /Users/bobby/Library/Application Support/k9s/plugins.yaml
Hotkeys:           /Users/bobby/Library/Application Support/k9s/hotkeys.yaml
Aliases:           /Users/bobby/Library/Application Support/k9s/aliases.yaml
Skins:             /Users/bobby/Library/Application Support/k9s/skins
Context Configs:   /Users/bobby/Library/Application Support/k9s/clusters
Logs:              /Users/bobby/Library/Application Support/k9s/k9s.log
Benchmarks:        /Users/bobby/Library/Application Support/k9s/benchmarks
ScreenDumps:       /Users/bobby/Library/Application Support/k9s/screen-dumps

From here I can see exactly where k9s is loading my config from. I’d encourage you to run this to save yourself some time chasing file paths

Hotkeys #

The documentation for hotkeys is pretty straight forward:

Create a file named $XDG_DATA_HOME/k9s/hotkeys.yaml

$XDG_DATA_HOME on MacOS is considered $HOME/Application Support/ while on Linux it’ll be $HOME/.config or even $HOME/.local/config.

Add the following to your hotkeys.yaml. You can use resource name/short name to specify a command ie same as typing it while in command mode.

If you’re a long time user of k9s it appears there was a configuration change, so you’ll want to make sure it’s hotkeys.yaml plural not hotkey.yaml.

Here’s my hotkeys.yaml cribbed right from the README.md of the repo. I added a shortcut to events with Shift+3 and rbac with Shift+4.

#  $XDG_CONFIG_HOME/k9s/hotkeys.yaml
hotKeys:
  # Hitting Shift-0 navigates to your pod view
  shift-0:
    shortCut:    Shift-0
    description: Viewing pods
    command:     pods
  # Hitting Shift-1 navigates to your deployments
  shift-1:
    shortCut:    Shift-1
    description: View deployments
    command:     dp
  # Hitting Shift-2 navigates to your xray deployments
  shift-2:
    shortCut:    Shift-2
    description: Xray Deployments
    command:     xray deploy
  # Hitting Shift-3 shows K8s events
  shift-3:
    shortCut:    Shift-3
    description: events
    command:     events
  # Hitting Shift-4 will show RBAC
  shift-4:
    shortCut:    Shift-4
    description: RBAC list
    command:     rb

  # Hitting Shift-S view the resources in the namespace of your current selection
  shift-s:
    shortCut:    Shift-S
    override:    true # => will override the default shortcut related action if set to true (default to false)
    description: Namespaced resources
    command:     "$RESOURCE_NAME $NAMESPACE"
    keepHistory: true # whether you can return to the previous view

Now my new favorite Shift+2 will give me a user friendly view of everything going on. X-Ray is worthy of its own blog post but the short version is you get a visual tree of a given resource, and in this case it’s deployments.

Now Shift+3 will show me events, very handy for debugging. Shift+4 will now show me k9s matrix of permissions for roles.

Bonus points: when we press ? the help screen displays our custom hotkeys and the description provided!

Alternative #

Most of this is targeting to quickly see what’s running in a given namespace. X-Ray view on deployments does that for me but another option is the workloads view. It will list all resources and you can filter with / just like other screens. While this is helpful, I find the visual tree a nice way to group resources.