Kubectl Change | Current Context
Since kubectl is written in Go, this feature leverages existing libraries but extends the cmd/config package.
: You may have an environment variable $KUBECONFIG pointing to a different file, or you're using a shell alias that hardcodes --context .
When you run kubectl get pods , you are implicitly using the —the active pointer to one of these predefined context bundles. kubectl change current context
kubectl config get-contexts
This piece provides an exhaustive guide to understanding, changing, and mastering Kubernetes contexts. Since kubectl is written in Go, this feature
Before you switch, see what's available:
┌─ Kubectl Context Manager ────────────────────────────────────────┐ │ Actions: [Enter] Switch [d] Describe [r] Rename [x] Delete │ └──────────────────────────────────────────────────────────────────┘ │ Name Cluster Namespace Auth Info │ │ > production-aws aws-prod-cluster default admin-user │ │ staging-aws aws-stage-cluster backend dev-user │ │ development-local docker-desktop kube-system default │ │ * gke-dev-01 gke-cluster-us monitoring gke-sa │ < Current │ │ └──────────────────────────────────────────────────────────────────┘ Context: gke-dev-01 | Cluster: gke-cluster-us | User: gke-sa Since kubectl is written in Go
The command that serves as the gatekeeper for this operation is:
Before changing a context, you must understand what it encapsulates. A in Kubernetes is a named set of three parameters that tells kubectl exactly where and how to talk to a cluster:
export KUBECONFIG_CONTEXT=prod-eks kubectl get nodes # Uses prod-eks without permanently switching