# Set once kubectl set-context --namespace=payments kubectl get pods kubectl get services kubectl get deployments Override for a single command kubectl get pods --namespace=audit # operates in 'audit' 4.2 Interaction with --all-namespaces The --all-namespaces flag (or -A ) explicitly overrides any namespace setting—including the context default—and operates across all namespaces. This is consistent with the precedence rule: the imperative flag takes highest priority. 4.3 Namespace Existence and Validation Crucially, kubectl set-context --namespace does not verify that the specified namespace exists in the target cluster. The validation occurs at the moment of a resource operation (e.g., get , create ). If the namespace does not exist, the API server returns:
kubectl set-context prod-ops --namespace=monitoring The context becomes: kubectl set-context namespace
The command kubectl set-context --namespace allows a user to bind a default namespace to a specific context —a named cluster-user pair stored in the kubeconfig file. Once set, all subsequent kubectl operations that support namespace scoping implicitly execute within that default namespace unless explicitly overridden. The validation occurs at the moment of a