kubectx — Fast Kubernetes Context & Namespace Switching
Switch between Kubernetes clusters and namespaces instantly with kubectx and kubens, essential tools for multi-cluster workflows.
Agent 可直接安装
这个资产可安装;Agent 先选择当前运行时、检查安装计划,再运行匹配命令。
npx -y tokrepo@latest install 5edfcecc-3997-11f1-9bc6-00163e2b0d79 --target codex先 dry-run 确认安装计划,再运行此命令。
What it is
kubectx is a pair of CLI tools (kubectx for cluster contexts, kubens for namespaces) that simplify switching between Kubernetes clusters and namespaces. Instead of typing kubectl config use-context my-long-cluster-name, you type kubectx my-cluster. Tab completion and fuzzy matching make navigation even faster across many clusters.
DevOps engineers and developers working with multiple Kubernetes clusters benefit most from kubectx. If you manage staging, production, and development clusters, kubectx eliminates the friction of context switching.
How it saves time or tokens
kubectx saves seconds on every context switch, which adds up to minutes per day for multi-cluster operators. The previous context shortcut (kubectx -) lets you toggle between two clusters like cd - in a shell. kubens provides the same speed for namespace switching, avoiding the verbose kubectl config set-context commands.
How to use
- Install kubectx via Homebrew or download the script
- Run
kubectxto list contexts orkubectx <name>to switch - Run
kubensto list namespaces orkubens <name>to switch
Example
# Install
brew install kubectx
# List all contexts
kubectx
# Output: dev-cluster, staging-cluster, prod-cluster
# Switch context
kubectx prod-cluster
# Switched to context 'prod-cluster'
# Switch back to previous
kubectx -
# Switched to context 'dev-cluster'
# Switch namespace
kubens monitoring
# Context 'dev-cluster' set to namespace 'monitoring'
# Interactive fuzzy selection (with fzf)
kubectx # launches fzf picker if installed
Related on TokRepo
- DevOps tools — Browse Kubernetes and infrastructure tools
- Featured workflows — Discover top-rated workflows
Common pitfalls
- kubectx modifies your kubeconfig context; running commands in another terminal will use the switched context too
- Renaming contexts with
kubectx new=oldis convenient but can confuse automation that relies on original names - kubens only works within the current context; switch context first if you need a different cluster's namespace
常见问题
kubectx switches between Kubernetes cluster contexts (which cluster kubectl talks to). kubens switches between namespaces within the current context (which namespace kubectl targets by default). Both ship together in the kubectx package.
Yes. If fzf (fuzzy finder) is installed, running kubectx without arguments opens an interactive fuzzy picker. This is useful when you have many clusters with similar names.
Yes. Use `kubectx new-name=old-name` to rename a context. This is helpful for giving short, memorable names to clusters with auto-generated long names from cloud providers.
Yes. kubectx works with any kubeconfig file, regardless of the Kubernetes distribution. EKS, GKE, AKS, k3s, minikube, and kind are all supported.
kubectx is safe in that it only modifies which context is active in your kubeconfig. However, switching to a production context means subsequent kubectl commands affect production. Use caution and consider visual indicators like kube-ps1 to show the current context in your prompt.
引用来源 (3)
- kubectx GitHub— Fast Kubernetes context and namespace switching
- kubectx README— kubectx and kubens CLI utilities
- Kubernetes Documentation— Kubernetes context management via kubeconfig
TokRepo 相关
讨论
相关资产
Kubero — Self-Hosted PaaS for Kubernetes with Git Push Deployments
Deploy applications to Kubernetes with Heroku-style git push workflows. Kubero provides a web UI, automatic SSL, built-in CI/CD pipelines, and add-on marketplace without requiring deep Kubernetes expertise.
SkyPilot — Run AI Workloads on Any Cloud or Kubernetes
SkyPilot is an open-source framework for running AI workloads across any cloud provider or Kubernetes cluster with automatic cost optimization and unified management.
Polars — Blazingly Fast DataFrame Library in Rust
Polars is an extremely fast DataFrame library written in Rust with bindings for Python, Node.js, and R. Uses Apache Arrow columnar format, lazy evaluation, and multi-threaded query execution. The modern alternative to pandas for data engineering and analytics.
kube-hunter — Kubernetes Security Testing from an Attacker Perspective
kube-hunter is an open-source tool by Aqua Security that hunts for security weaknesses in Kubernetes clusters by simulating an attacker's discovery and exploitation process.