Kubens. DIY with FZF
In my work daily routine, I often need to switch between namespaces(less frequently contexts) in kubernetes and I used to use kubectx/kubens tools. Recently I started using FZF, mostly as a file finder and for fuzzy search in command line history.
I was wonder if I can apply FZF somewhere else. I tried to make my own kubens. What requirements do I have?
- show all namespaces for the current context
- select with fuzzy search
- switch to selected
- highlight current namespace (optional)
For intermediate scripts I use fish shell, a final script I show in fish shell and bash/zsh.
Show namespaces
Default kubectl command:
|
|
Select with fuzzy search
To select namespace we pipe previous command with FZF:
|
|
We have to get rid of headers and choose only namespace name column:
|
|
Swith to selected
|
|
bash/zsh:
|
|
Conclusion
We can add it to fish functions and invoke by name(knmps
).
Add knmsp.fish to ~/.config/fish/functions/knmsp.fish
|
|