Kubectl Config Set Context Page

A context acts as a "shortcut" for your CLI requests. Instead of manually passing flags for the API server address, authentication credentials, and target namespace for every command, you can bundle them into a named context and switch between them as needed. The target Kubernetes API server.

# Set the --namespace flag for the CURRENT context kubectl config set-context --current --namespace=db-migration

# Unset the namespace override kubectl config set-context --current --namespace= kubectl config set context

: Specifies the user credentials to use for this context.

This command updates the existing context my-context with a new namespace. A context acts as a "shortcut" for your CLI requests

get_k8s_context() echo "$(kubectl config current-context 2>/dev/null)"

Did you just modify your current context with the wrong namespace and forget what the original was? Don't panic. Kubernetes stores the original cluster and user information in the context. You can reset just the namespace: # Set the --namespace flag for the CURRENT

Before you can set it, you have to understand it. A kubectl context is a bundle of three pointers:

This example creates a "development" context that links a "dev-cluster" to a "dev-user":