Namespaces
Namespaces
A virtual cluster inside the cluster: a name scope for objects, and a place to attach quotas and policies.
graph TB
subgraph cluster
subgraph ns1 [namespace: dev]
P1[pod web] --- P2[pod db]
end
subgraph ns2 [namespace: prod]
P3[pod web] --- P4[pod db]
end
N[nodes, PVs - not namespaced]
end
kubectl get ns
kubectl create ns dev
kubectl get pods -n dev
kubectl get pods -A
kubectl config set-context --current --namespace=dev
kubectl api-resources --namespaced=false # what lives outside namespaces
Namespaced: Pods, Deployments, Services, ConfigMaps, Secrets, PVCs, HTTPRoutes. Not namespaced: Nodes, PersistentVolumes, StorageClasses, ClusterRoles, CRDs.
The four you get for free: default, kube-system, kube-public,
kube-node-lease. Never deploy your own work into kube-system.
Deleting a namespace deletes everything in it, with no confirmation and no undo.
Check kubectl config get-contexts before you type it.