Skip to content

kubectl context management

kubectl context management refers to the administration of kubectl configuration parameters, which determine how the command-line tool communicates with different Kubernetes clusters.^[400-devops__06-Kubernetes__k8s.md]

Configuration

Configuration settings for kubectl are typically loaded from specific file locations. By default, kubectl accesses the configuration file located at ${HOME}/.kube/config.^[400-devops__06-Kubernetes__k8s.md] Users can override this location by using the --kubeconfig flag, setting the $KUBECONFIG environment variable, or by using the kubectl config subcommand.^[400-devops__06-Kubernetes__k8s.md]

Contexts

In Kubernetes, a "context" is a group of access parameters. Each context contains a cluster, a user, and a namespace.

Listing Contexts

To display all available contexts defined in the configuration file, use the following command:

kubectl config get-contexts

Viewing Current Context

To identify the currently active context, use:

kubectl config current-context

Switching Contexts

To switch the active context (e.g., to a context named minikube), use the use-context subcommand:

kubectl config use-context minikube
  • k8s
  • [[namespace]]

Sources