kns is a terminal user interface (TUI) tool for quickly switching the active namespace in your Kubernetes kubeconfig file. It lists all namespaces in your current Kubernetes context and lets you interactively select one, updating your kubeconfig accordingly. It is built on top of the bubbletea framework available at https://github.com/charmbracelet/bubbletea.
- You will need a valid kubeconfig file that has access to a Kubernetes cluster.
- The
KUBECONFIGenvironment variable should be set to point to your kubeconfig file, or it will default to~/.kube/config. In-cluster configurations will not work. - You should have relevant permissions to list all namespaces in the cluster.
- You should have permission to read a namespace from the kubernetes cluster.
- You should have write permissions to update the kubeconfig file.
- Lists all namespaces in the current Kubernetes context.
- Interactive TUI for namespace selection using keyboard navigation.
- Fuzzy search — press
/to filter namespaces by partial name (e.g.fl,kube). - Updates your kubeconfig file to set the selected namespace as default for the current context.
- Works with the kubeconfig file specified by the
KUBECONFIGenvironment variable or defaults to~/.kube/config. - Direct command-line mode to switch namespace without opening the TUI.
-
Download the latest release binary from the releases page.
-
If you have Go installed, you can also run:
go install github.com/prit342/kns@latestClone the repository and build the binary:
git clone https://github.com/prit342/kns.git
cd kns
go build -o kns ../kns| Key | Action |
|---|---|
↑ / ↓ |
Navigate the namespace list |
/ |
Enter search mode — type to filter by partial name |
Esc (in search) |
Clear the filter and return to the full list |
Enter or Space |
Select the highlighted namespace |
Esc (outside search) |
Quit without making changes |
Ctrl+C |
Quit without making changes |
kns <namespace>- Go 1.24.1 or higher.
- Access to a Kubernetes cluster and a valid kubeconfig file.
main.go: Entry point for the CLI application.k8s/service.go: Kubernetes client logic for connecting to a K8s cluster, listing namespaces, and caching the parsed kubeconfig.k8s/interface.go: Interface definitions.k8s/update_kubeconfig.go: Logic for updating the kubeconfig file with the selected namespace (uses the cached config — no second file read).tui/tui.go: TUI implementation using Bubble Tea and Bubbles.
- Add functionality to run
kns <namespace>to switch to a specific namespace directly from the command line. - Add fuzzy search / filtering in the TUI.
- Add various tests.
