A simple and fast CLI tool for switching between Kubernetes namespaces with interactive filtering.
- 🚀 Interactive namespace selection with fuzzy search
- ⌨️ Direct namespace switching via command-line argument
- 🔍 Real-time filtering as you type
- ✅ Shows current namespace
- 📝 Updates your kubeconfig automatically
- ⚡ Tab completion for namespaces (bash, zsh, fish)
Build from source:
git clone git@github.com:michizubi-SRF/kns.git
cd kns
go build -o kns
sudo mv kns /usr/local/bin/Enable tab completion for namespace names by sourcing the appropriate completion script for your shell.
Quick test in current session:
# Ensure completion system is loaded (usually already done in .zshrc)
autoload -Uz compinit && compinit
# Load kns completion
source <(./kns completion zsh)
# Now try: ./kns [TAB]Permanent setup - Add to your ~/.zshrc:
# Add this line to enable kns completion
source <(kns completion zsh)Or place the completion file in your $fpath:
kns completion zsh > /usr/local/share/zsh/site-functions/_kns
# Then restart your shell or run: compinitAdd to your ~/.bashrc:
source <(kns completion bash)Or save the completion script to a file:
kns completion bash > /usr/local/etc/bash_completion.d/knsSave the completion file to Fish's completion directory:
kns completion fish > ~/.config/fish/completions/kns.fishAfter setup, you can use tab completion:
kns <TAB> # Shows all available namespaces
kns prod<TAB> # Completes to 'production' if it existsSimply run kns without arguments to get an interactive list:
kns- Use arrow keys to navigate
- Start typing to filter namespaces
- Press Enter to switch to the selected namespace
- Press Ctrl+C to cancel
Provide the namespace name as an argument:
kns production
kns dev
kns kube-system# Interactive selection
$ kns
Use the arrow keys to navigate: ↓ ↑ → ←
? Select Namespace (current: default):
▸ default
kube-system
kube-public
production
staging
dev
# Direct switching
$ kns production
Switched to namespace 'production'
# Trying to switch to current namespace
$ kns production
Already in namespace 'production'- Go 1.21 or later
- Valid kubeconfig file
- Access to a Kubernetes cluster
kns reads your kubeconfig file, lists all available namespaces from your cluster, and updates the namespace for your current context. The change persists across kubectl commands.