Namespaces & Contexts
Beginner
Overview
Namespaces partition a cluster into virtual sub-clusters, so teams or environments can share one physical cluster without colliding. Most commands default to the 'default' namespace.
Use -n <namespace> to target one, or -A / --all-namespaces to see everything. A context bundles a cluster, user, and namespace; kubectl config use-context switches between them.
Setting a default namespace for your current context saves typing -n on every command.
Cheatsheet
kubectl get nsList namespaceskubectl get pods -n kube-systemTarget a namespacekubectl create namespace devCreate a namespacekubectl config get-contextsList available contextskubectl config use-context prodSwitch clusterskubectl config set-context --current --namespace=devSet a default namespaceTry it
A safe, simulated terminal. Run the suggested commands to see typical output.
simulated terminal
Type a command and press Enter, or click a suggestion below to run it.
Quick quiz
1. What problem do namespaces solve?
2. Which flag shows resources across every namespace?