π Define plugins to integrate tools with k9s
k9s + your-fav-tool = π
Warning
Work in progress... Options and layout may change in future K9s releases as this feature solidifies.
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 plugindescription
: will be printed next to the shortcut in the k9s menuscopes
: defines a collection of resources name/short-name for the views associated with the plugin. You can specifyall
to provide this shortcut for all views.command
: represents ad-hoc commands the plugin runs upon activationbackground
: specifies whether or not the command runs in the backgroundargs
: 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:
Variable | Description |
---|---|
$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- ! |
Info
Take a look at some of the Community Custom Plugins contributed by your K9sers friends.
Example plugin
The example plugin runs the following kuebctl
command when hitting the Ctrl-L
key combination in the pods
view.
kubectl logs -f $NAME -n $NAMESPACE --context $CONTEXT`
# $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