Plugins


Overview

K9s allows you to extend your command line and tooling by defining your very own cluster commands via plugins. K9s looks at $XDG_CONFIG_HOME/k9s/plugins.yaml to locate all available plugins. You can further extend plugins behavior in a context specific configuration using $XDG_DATA_HOME/k9s/clusters/clusterX/contextY/plugins.yaml.

A plugin is defined as follows:

  • Shortcut option represents the key combination a user would type to activate the plugin
  • Description will be printed next to the shortcut in the k9s menu
  • Scopes defines a collection of resources name/short-name for the views associated with the plugin. You can specify all to provide this shortcut for all views.
  • Command represents ad-hoc commands the plugin runs upon activation
  • Background specifies whether or not the command runs in the background
  • Args specifies the various arguments that should apply to the command above

K9s does provide additional environment variables for you to customize your plugins arguments. Currently, the available environment variables are as follows:

  • $NAMESPACE – the selected resource namespace
  • $NAME – the selected resource name
  • $CONTAINER – the current container if applicable
  • $FILTER – the current filter if any
  • $KUBECONFIG – the KubeConfig location.
  • $CLUSTER the active cluster name
  • $CONTEXT the active context name
  • $USER the active user
  • $GROUPS the active groups
  • $POD while in a container view
  • $COL-<RESOURCE_COLUMN_NAME> use a given column name for a viewed resource. Must be prefixed by COL-!

NOTE: Take a look at some of the Community Custom Plugins contributed by your K9sers friends.


Work in progress... Options and layout may change in future K9s releases as this feature solidifies.


Example

This defines a plugin for viewing logs on a selected pod using ctrl-l mnemonic.

# $XDG_CONFIG_HOME/k9s/plugins.yaml
plugins:

  # Defines a plugin to provide a `ctrl-l` shortcut to tail the logs while in pod view.
  fred:
    # Define a mnemonic to invoke the plugin
    shortCut: Ctrl-L
    # What will be shown on the K9s menu
    description: Pod logs
    # Collections of views that support this shortcut. (You can use `all`)
    scopes:
    - po
    # The command to run upon invocation. Can use Krew plugins here too!
    command: kubectl
    # Whether or not to run the command in background mode
    background: false
    # Defines the command arguments
    args:
    - logs
    - -f
    - $NAME
    - -n
    - $NAMESPACE
    - --context
    - $CONTEXT

 Back



© 2024 Imhotep Software LLC. All materials licensed under Apache v2.0