Learn how to use kubectx and kubens as native kubectl plugins through Krew
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.
Install both kubectx and kubens as kubectl plugins:
kubectl krew install ctxkubectl 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.
All standard kubectx operations work with the kubectl ctx prefix:
# List all contextskubectl ctx# Switch to a specific contextkubectl ctx minikube# Switch to previous contextkubectl ctx -# Show current contextkubectl ctx -ckubectl ctx --current# Rename a contextkubectl ctx new-name=old-name# Rename current contextkubectl ctx new-name=.# Unset current contextkubectl ctx -ukubectl ctx --unset# Delete a contextkubectl ctx -d context-name# Delete current contextkubectl ctx -d .
All standard kubens operations work with the kubectl ns prefix:
# List all namespaceskubectl ns# Switch to a namespacekubectl ns kube-system# Switch to previous namespacekubectl ns -# Show current namespacekubectl ns -ckubectl ns --current# Force switch to a namespace (even if it doesn't exist)kubectl ns non-existent-ns --forcekubectl ns non-existent-ns -f