Skip to main content
kubectx and kubens can be installed and used as native kubectl plugins through Krew, the kubectl plugin manager. This provides seamless integration with your kubectl workflow.

Installation via Krew

1

Install Krew

If you don’t have Krew installed, follow the Krew installation guide.
2

Install the plugins

Install both kubectx and kubens as kubectl plugins:
kubectl krew install ctx
kubectl krew install ns
3

Verify installation

Check that the plugins are installed correctly:
kubectl plugin list
You should see kubectl-ctx and kubectl-ns in the output.
Krew installation does not include shell completion scripts. If you need tab completion, install the scripts manually or use another installation method like Homebrew.

Usage as kubectl Plugins

Once installed via Krew, the tools are available as kubectl ctx and kubectl ns instead of standalone commands.

kubectl ctx Commands

All standard kubectx operations work with the kubectl ctx prefix:
# List all contexts
kubectl ctx

# Switch to a specific context
kubectl ctx minikube

# Switch to previous context
kubectl ctx -

# Show current context
kubectl ctx -c
kubectl ctx --current

# Rename a context
kubectl ctx new-name=old-name

# Rename current context
kubectl ctx new-name=.

# Unset current context
kubectl ctx -u
kubectl ctx --unset

# Delete a context
kubectl ctx -d context-name

# Delete current context
kubectl ctx -d .

kubectl ns Commands

All standard kubens operations work with the kubectl ns prefix:
# List all namespaces
kubectl ns

# Switch to a namespace
kubectl ns kube-system

# Switch to previous namespace
kubectl ns -

# Show current namespace
kubectl ns -c
kubectl ns --current

# Force switch to a namespace (even if it doesn't exist)
kubectl ns non-existent-ns --force
kubectl ns non-existent-ns -f

Interactive Mode with fzf

When fzf is installed, the kubectl plugin versions support the same interactive fuzzy-search functionality:
# Interactive context selection
kubectl ctx

# Interactive namespace selection
kubectl ns
The plugin automatically detects fzf and enables interactive mode when you run the commands without arguments.

Disabling Interactive Mode

To disable fzf integration even when fzf is installed:
export KUBECTX_IGNORE_FZF=1
Or pipe the output to another command:
kubectl ctx | cat
kubectl ns | grep prod

Advantages of kubectl Plugin Usage

All your Kubernetes tools are accessible through the kubectl command, providing a consistent user experience.
Users can discover available plugins using kubectl plugin list or kubectl krew search.
Update both tools with a single command:
kubectl krew upgrade ctx ns
Krew handles platform-specific installation details automatically.

Switching Between Standalone and Plugin Usage

You can have both the standalone binaries and kubectl plugins installed simultaneously. They work identically:
# These are equivalent:
kubectx minikube
kubectl ctx minikube

# These are also equivalent:
kubens kube-system
kubectl ns kube-system
If you have both installed, ensure they’re the same version to avoid inconsistent behavior.

Uninstalling

To remove the kubectl plugins:
kubectl krew uninstall ctx ns

Plugin Information

View detailed information about the plugins:
# Show plugin info
kubectl krew info ctx
kubectl krew info ns

# Show installed version
kubectl ctx --version
kubectl ns --version

Build docs developers (and LLMs) love