"TIL: k9s plugins" was originally published on kevingimbel.de.

TIL: k9s plugins

k9s is an awesome terminal UI and tool to work with Kubernetes clusters. I’m using it daily for basically all my Kubernetes related work tasks.

Recently I learned there’s a super straight forward way of adding “plugins” to k9s, which are basically shortcuts for calling (shell) commands.

Take the following example from my $XDG_CONFIG_HOME/k9s/plugins.yaml file

    shortCut: Ctrl-L
    confirm: false
    description: Grafana
    - pods
    background: true
    command: open
    - https://my-grafana.tld/d/abcdefghi/my-dashboard?orgId=1&var-Datasource=prometheus-$CLUSTER&var-Namespace=$NAMESPACE&var-app_kubernetes_io_name=All&var-Pod=$COL-NAME&from=now-6h&to=now

Let’s have a look at each line:

  • shortCut defines the key combination which invokes the plugin
  • confirm can be true or false and will show a confirmation dialog if set to true before invoking the plugin
  • description is the name shown in the UI
  • scopes defines on what resources the plugin is available (will be hidden in the UI otherwise)
  • background defines if the plugin runs in the background or re-uses the same terminal (minimising k9s)
  • command is the command or tool to be invoked. It can be any command available in the shell, like open (to open a URL), kubectl, …
  • args is a list of arguments passed to the command
A screenshot showing the ctrl-l shortcut of the Grafana plugin

When I hit CTRL-L, the open command is invoked and open Grafana in my browser. It passes all relevant variables to the dashboard:

  • $CLUSTER is the name of the current cluster
  • $NAMESPACE is the currently active namespace
  • $COL-NAME is the Name in the current column (the selected pod in the list of pods)

It’s a super powerful shortcut do view metrics about a pod in an instant, and made my life a lot easier!

More fields can be seen in the documentation at https://k9scli.io/topics/plugins/

k9s itself is already a powerful tool, but this extensibility just makes it so much more flexible!

Additional links