Simplify working with kubectl on the command line with skim.
kube-fuzzy aims to replace kubectl with an interactive prompt by using skim.
kube-fuzzy.sh
includes 2 functions to source in your shell:
kube_fuzzy
, to provide the main functionality- and
kube_define
, a helper function for extending that functionality.
kube-fuzzy
's default aliases are designed to mimic common aliases used for kubectl. The goal is to change the flow of running these commands, for eg. kgpo | grep name; kdpo full-pod-name | less; krmpo full-pod-name
into a single easier to control, kgp
.
The default aliases are:
kgp
, to replacekubectl get pods
,edit pods
, so onkgd
, to replacekubectl get deployments
,edit deployments
, so onkgs
, to replacekubectl get services
- and
kgsec
, to replacekubectl get secrets
You can also call the kube_fuzzy
function directly, like so:
kube_fuzzy pods
or with bat
installed:
kube_fuzzy pods --events
which will place the Events:
part of the preview on the top to read updates more easily.
kgp
, kgd
and kgs
by default use this flag.
- Note this may cause a "double output" effect if the resource reports no events when described (eg.
secrets
), so only use with relevant resources.
The default keybinds are:
ctrl-e
: Edit selected resources after exitctrl-t
: Delete currently highlighted resourcectrl-b
: Describe selected resources after exitctrl-l
: Log selected pod after exitctrl-k
: Get containers of selected pod, and display its logs in skctrl-o
: Base64 decode the data fields of selected secret after exitctrl-n
: No action, defaults to outputting selected objects
If you would prefer other keybinds or these interfere with your terminal, see Configuring#Keybinds.
Keybinds will queue an action to be performed after accepting a selection. You can see the last queued action at the top of the preview pane on the right side of the screen. To add more actions, see Configuring#Actions
- Note: This will only update with the preview window itself, which is limited by how fast
kubectl
can run.
- kubectl
- sk
- bash >= v4, zsh or similar. Fish cannot run the script
- Optional:
- bat, used for the --events formatting flag
-
Kubectl (if required)
brew install kubectl
-
Skim
brew install sk
-
Optionally, to use the
--events
flagbrew install bat
-
Kubectl (if required): see their install guide
-
Skim
dnf install skim
-
Optionally, to use the
--events
flagdnf install bat
-
Kubectl (if required)
pacman -S kubectl
-
Skim
pacman -S skim
-
Optionally, to use the
--events
flagpacman -S bat
-
Clone the repo where you want your installation to be
git clone https://github.com/paranoidcake/kube-fuzzy
-
cd
to the newly created directorycd kube-fuzzy
-
Depending on your shell, run:
-
Bash
echo "source $(pwd)/kube-fuzzy.sh" >> ~/.bashrc
-
Zsh
echo "source $(pwd)/kube-fuzzy.sh" >> ~/.zshrc
-
Or source it manually
- Note you will have to change the path in your
.bashrc
file if you move the kube-fuzzy.sh file
- Note you will have to change the path in your
-
-
Open a new shell or source your
.bashrc
file -
You're done!
By default kube-fuzzy.sh has 4 aliases which use the kube_fuzzy
command, and its optional --events flag:
kgp="kube_fuzzy pods --events"
, for podskgd="kube_fuzzy deployments --events"
, for deploymentskgs="kube_fuzzy services --events"
, for serviceskgsec="kube_fuzzy secrets"
, for secrets
These aliases are defined at the end of the kube-fuzzy.sh
file, where you can change, remove, or add to them.
You can also call the kube_fuzzy
command from your .bashrc
file after sourcing, if you prefer to have your aliases there.
By default keybinds are defined in files in the keybinds/
folder, with the format action=binding
, seperated by new lines.
action
must match what comes after kube_
in it's function name in actions.sh
.
- For example, the action name for
kube_describe()
isdescribe
.
They can be defined:
-
Through
kube_define
, which accepts a resource (eg.pods
orany
), and then a string of space seperated keybinds.- Eg.
kube_define pods 'logs=ctrl-l containers=ctrl-k'
, which will:- Create a file 'pods' in
keybinds/
, which will be loaded wheneverkube_fuzzy
is called onpods
- Define the keybind
ctrl-l
to callkube_logs()
fromactions.sh
- Define the keybind
ctrl-k
to callkube_containers()
fromactions.sh
- Create a file 'pods' in
- Eg.
-
Or manually by creating / editing a file in
keybinds/
, following the above format. You can view some examples in theany
,pods
andsecrets
files that come with the repo.
Keybinds are loaded automatically based on the resource name. kube_fuzzy
will check if there is a file matching the resource name (eg. pods
) and read from it.
The any
file's keybinds are also applied on any resource type.
This allows for global and resource-specific keybinds to be defined.
For a list of accepted keys see:
Available keys from the sk man page
AVAILABLE KEYS: (SYNONYMS)
ctrl-[a-z]
ctrl-space
ctrl-alt-[a-z]
alt-[a-zA-Z]
alt-[0-9]
f[1-12]
enter (ctrl-m)
space
bspace (bs)
alt-up
alt-down
alt-left
alt-right
alt-enter (alt-ctrl-m)
alt-space
alt-bspace (alt-bs)
alt-/
tab
btab (shift-tab)
esc
del
up
down
left
right
home
end
pgup (page-up)
pgdn (page-down)
shift-up
shift-down
shift-left
shift-right
alt-shift-up
alt-shift-down
alt-shift-left
alt-shift-right
or any single character
Actions are defined in the actions.sh
file in the same directory as kube-fuzzy.sh
.
To implement a new action, define it as a function in actions.sh
with the prefix kube_
. It must accept a kubernetes resource for argument 1, and a space seperated list of names of those resources for argument 2.
To get your action called from within kube-fuzzy.sh
, give it a keybind, as described in Configuring#Keybinds
Some exit codes are available, which kube-fuzzy.sh
will print an error message for. To utilise them simply return their value.
Currently they are:
Exit Code | Error |
---|---|
3 | Incompatible resource |
4 | Incompatible with multiple resources selected |
kube-fuzzy.sh
will propagate any code recieved from a function called in actions.sh
to the shell it was executed in
- Define the function in
actions.sh
function kube_describe() {
resource="$1"
result="$2"
kubectl describe "$resource" "$result"
}
-
Give it a keybind by calling
kube_define
from your shell:kube_define any 'describe=ctrl-b'
(This can be done in other ways, see Configuring#Keybinds for details)
-
It will now be runnable with
ctrl-b
when runningkube_fuzzy