A simple and fast CLI tool for switching between Kubernetes contexts with an interactive interface.
- 🚀 Fast and lightweight
- 🎯 Interactive context selection with arrow key navigation
- ⌨️ Type-to-filter contexts in real-time
- 🔄 Direct context switching via argument
- 🔍 Fuzzy matching for context names
- 📋 List all available contexts
- 🎨 Colored output with context details
- ✅ Built with promptui for smooth interactive experience
# Interactive mode - select context with arrow keys
ktx
# Direct switch - provide context name
ktx production
# List all contexts
ktx listgit clone https://github.com/michizubi-SRF/ktx
cd ktx
go build -o ktx
sudo mv ktx /usr/local/bin/Simply run ktx to launch the interactive context selector:
ktxFeatures in interactive mode:
- ↑/↓ Arrow keys: Navigate through contexts
- Type to filter: Start typing to filter contexts in real-time
- Enter: Select and switch to the highlighted context
- Ctrl+C: Exit without changing context
The tool shows context details including cluster, namespace, and user after selection.
Provide the context name as an argument to switch directly:
ktx production-clusterList all available contexts:
ktx list
# or
ktx lsThe tool supports fuzzy matching. If you provide a partial name, it will:
- Switch automatically if there's only one match
- Show suggestions if there are multiple matches
ktx prod # Will switch to 'production-cluster' if it's the only matchShow help information:
ktx help
# or
ktx -hThe tool uses your standard kubeconfig file:
- Default:
~/.kube/config - Custom: Set the
KUBECONFIGenvironment variable
export KUBECONFIG=/path/to/your/kubeconfig
ktxktx provides an interactive terminal UI for switching Kubernetes contexts:
- Interactive Mode: Uses promptui to provide a smooth selection experience with arrow key navigation and real-time filtering
- Context Management: Reads your kubeconfig file using the Kubernetes client-go library
- Switching: Updates the
current-contextfield in your kubeconfig when you select a new context - Context Details: Shows cluster, namespace, and user information for the selected context
- k8s.io/client-go - Kubernetes client library
- github.com/manifoldco/promptui - Interactive prompt UI
- Go 1.21 or higher
- Access to a kubeconfig file
# Clone the repository
git clone https://github.com/michizubi-SRF/ktx
cd ktx
# Install dependencies
go mod download
# Run locally
go run main.go
# Build
go build -o ktx