# kubectx

> CLI tools to quickly switch between Kubernetes contexts and namespaces with fuzzy search support

Stars: 20.1k · Language: Go · License: Apache-2.0 · Categories: Dev Tools

- Repository: https://github.com/ahmetb/kubectx
- Website: https://kubectx.dev
- Page: https://www.trmn.sh/tools/kubectx

## Install

- Homebrew: `brew install kubectx`
- apt: `sudo apt install kubectx`
- Krew: `kubectl krew install ctx && kubectl krew install ns`

## Overview

kubectx and kubens are complementary CLI utilities that simplify Kubernetes cluster and namespace management. kubectx allows users to switch between different Kubernetes contexts (clusters) defined in their kubeconfig, supporting quick context switching, renaming contexts with aliases, and launching isolated or read-only shells for specific contexts. kubens provides similar functionality for Kubernetes namespaces, enabling rapid namespace switching within the current context.

Both tools integrate with fzf to provide interactive fuzzy search menus when selecting contexts or namespaces. They support tab completion across bash, zsh, and fish shells, eliminating the need to remember long context names. kubectx includes a previous context feature using the `-` flag, similar to `cd -`, and kubens can switch to namespaces that don't yet exist using the `-f` flag.

The tools are designed for Kubernetes developers, DevOps engineers, and platform operators who frequently work across multiple clusters or namespaces. Installation is available through system package managers (Homebrew, apt, pacman), Windows package managers (Chocolatey, Scoop, winget), or as kubectl plugins via Krew. The utilities can be customized with environment variables for colors and behavior, including the ability to disable color output entirely.

### Installation

```bash
# via Homebrew
brew install kubectx
```

```bash
# via apt
sudo apt install kubectx
```

```bash
# via Krew
kubectl krew install ctx && kubectl krew install ns
```

![kubectx demo](https://media.trmn.sh/cached/c5c7d4047ad61b0077275c08a6a4711d10b2c97424d3b0b21ed353d6a0b8b971.gif)

![kubens demo](https://media.trmn.sh/cached/ed5020e6a66d5ee9cb40af1cf237c7b84176008fbb47510cda4e3781f26517d2.gif)

![kubectx interactive search with fzf](https://media.trmn.sh/cached/e33e4928cebbe6789acedc679d417c3023229453e76cd1ec823d8d5d1eb64d9c.gif)

## Alternatives

- [VHS](https://www.trmn.sh/tools/vhs.md): Generate terminal GIFs from code scripts for testing and demonstrating CLI tools (Go, 21.2k stars)
- [sops](https://www.trmn.sh/tools/sops.md): Editor for encrypted files supporting YAML, JSON, ENV, INI formats with AWS KMS, GCP KMS, Azure Key Vault, age, and PGP encryption (Go, 23.6k stars)
- [Task](https://www.trmn.sh/tools/go-task.md): Task runner and build tool that reads tasks from a YAML Taskfile, a simpler cross-platform alternative to Make. (Go, 16.3k stars)
- [asdf](https://www.trmn.sh/tools/asdf.md): Version manager that handles multiple language runtimes per project through plugins, using a single CLI and a .tool-versions file. (Go, 25.6k stars)
- [ipatool](https://www.trmn.sh/tools/ipatool.md): CLI for searching the App Store for iOS, iPadOS, tvOS, visionOS and macOS apps and downloading .ipa or macOS .pkg packages. (Go, 12.1k stars)

---

Canonical: https://www.trmn.sh/tools/kubectx
