The Kubernetes Context Switching Nightmare is Over

Published: (December 9, 2025 at 02:42 PM EST)
2 min read
Source: Dev.to

Source: Dev.to

Kubernetes context switching nightmare illustration

If you work with multiple Kubernetes clusters daily, you know the pain. Production, staging, development, that random test cluster someone spun up last month — they all live in your kubeconfig file, and switching between them feels like navigating a maze blindfolded.

I got tired of it. So I built kubecfg.

What is kubecfg?

kubecfg is a CLI tool that simplifies kubeconfig management. It lets you:

  • Add new cluster configs with custom names
  • List all your contexts at a glance
  • Switch contexts with optional namespace selection
  • Manage namespaces interactively
  • Rename contexts to something memorable
  • Remove contexts you no longer need
  • Merge multiple kubeconfig files

The killer feature? Interactive pickers with fuzzy selection. No more copy‑pasting long context names.

Quick Demo

Switching Context with Namespace

Switching context diagram

kubecfg use -n

The command opens an interactive picker for the context, then asks which namespace you want. Both selections happen in one flow.

Select context
  minikube
▸ production-eks
  staging-gke
  dev-local

✓ production-eks

Select namespace
  default
  kube-system
▸ backend-services
  frontend
  monitoring

✓ backend-services

Switched to context 'production-eks' with namespace 'backend-services'

Switch context only

kubecfg use production-eks

Switch with a specific namespace

kubecfg use production-eks -n backend-services

The -n flag is smart: use it without a value for interactive selection, or pass a namespace directly.

Installation

Homebrew (macOS)

brew tap kadirbelkuyu/tap
brew install kadirbelkuyu/tap/kubecfg

Go Install

go install github.com/kadirbelkuyu/kubecfg@latest

From Source

git clone https://github.com/kadirbelkuyu/kubecfg.git
cd kubecfg
go build -o kubecfg .
sudo mv kubecfg /usr/local/bin/

Commands in Detail

Adding a New Cluster

kubecfg add ~/Downloads/eks-config.yaml --name production-eks

The original file stays untouched. The context gets added to your main kubeconfig with the name you chose.

Listing All Contexts

kubecfg list

Output

CURRENT  NAME            CLUSTER         SERVER                              NAMESPACE
*        production-eks  production-eks  https://xxx.eks.amazonaws.com       backend
         staging-gke     staging-gke     https://xxx.gke.googleapis.com      -
         dev-local       minikube        https://192.168.49.2:8443           default

The asterisk shows your current context. - indicates the default namespace.

Interactive Context Switching

kubecfg use

No arguments needed. An interactive picker appears; use arrow keys to navigate, Enter to select.

Select context
  minikube
▸ production-eks
  staging-gke

✓ production-eks

Switched to context 'production-eks'

Namespace Management

Switch namespace for the current context

kubecfg ns

Interactive picker pulls namespaces directly from the cluster:

Select namespace
  default
  kube-system
▸ backend-services
  monitoring

✓ backend-services

Namespace set to 'backend-services'

Set namespace directly

kubecfg ns kube-system

Show current namespace

kubecfg ns current
# Output: backend-services

Renaming Contexts

kubecfg rename arn:aws:eks:us-east-1:123456789:cluster/prod production

Removing Contexts

kubecfg remove old-cluster

You’ll get a confirmation prompt:

Remove context 'old-cluster'? [y/N]:

Skip the prompt with --force:

kubecfg remove old-cluster --force

Merging Configs

kubecfg merge config1.yaml config2.yaml config3.yaml -o merged.yaml

All contexts, clusters, and users are combined into one file. Duplicates are handled gracefully.

Merging configs diagram

Back to Blog

Related posts

Read more »