A fast and intuitive Kubernetes context and namespace switcher for Fish shell.
- π Fast context switching with interactive selection using fzf
- π― Namespace management with fuzzy search
- π Multiple kubeconfig support - automatically discovers configs in
~/.kube/configand~/.kube/configs/ - π Context info display - shows current context, namespace, and kubeconfig path
- β‘ Tab completion for contexts and namespaces
- π¨ Syntax highlighting in fzf previews using bat
Install using Fisher:
fisher install aohoyd/kswitchThis plugin requires the following tools to be installed:
kubectl- Kubernetes command-line toolfzf- Fuzzy finder for interactive selectionyq- YAML processor for parsing kubeconfig filesfd- Fast file finder for discovering kubeconfig filesbat- Syntax highlighter for fzf previews (optional but recommended)
Switch between Kubernetes contexts with optional namespace specification.
# Interactive context selection with fzf
ks
# Switch to specific context
ks my-context
# Switch to context and set namespace
ks my-context my-namespace# Launch interactive context selector
ks
# Switch to production context
ks prod-cluster
# Switch to staging context and set namespace to monitoring
ks staging-cluster monitoringSwitch namespaces within the current context.
# Interactive namespace selection with fzf
kns
# Switch to specific namespace
kns my-namespace# Launch interactive namespace selector
kns
# Switch to kube-system namespace
kns kube-system
# Switch to default namespace
kns defaultDisplay current Kubernetes context information.
ksiCurrent KUBECONFIG: /home/user/.kube/configs/prod-cluster.yaml
Current context: prod-cluster
Current namespace: monitoring
The plugin automatically discovers kubeconfig files from:
~/.kube/config(default kubectl config)- All files in
~/.kube/configs/directory
~/.kube/
βββ config # Default kubectl config
βββ configs/
βββ prod-cluster.yaml
βββ staging-cluster.yaml
βββ dev-cluster.yaml
The plugin provides intelligent tab completion:
ks: Completes with available contexts, then namespaceskns: Completes with available namespaces
Both ks and kns support interactive mode when called without arguments:
- Context selection: Shows all available contexts from all kubeconfig files with file preview
- Namespace selection: Shows all namespaces in the current context
- Use arrow keys or type to filter results
- Press Enter to select, Escape to cancel
The plugin sets the following environment variable:
KUBECONFIG: Points to the currently active kubeconfig file
If you see "No contexts found in kubeconfig files":
- Ensure you have kubeconfig files in
~/.kube/configor~/.kube/configs/ - Verify your kubeconfig files are valid YAML
- Check that contexts are properly defined in your kubeconfig files
Ensure all prerequisites are installed:
# Check if required tools are available
which kubectl fzf yq fd batEnsure your kubeconfig files have proper read permissions:
chmod 600 ~/.kube/config ~/.kube/configs/*