Namespaces
Namespaces
A virtual cluster inside the cluster: a name scope for objects, and the place to attach quotas, RBAC and network 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, StorageClasses - 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 | Cluster-scoped |
|---|---|
| Pods, Deployments, Services, ConfigMaps, Secrets, PVCs, Roles | Nodes, PersistentVolumes, StorageClasses, ClusterRoles, CRDs, Namespaces |
Built in: default, kube-system, kube-public, kube-node-lease. Never
deploy your own work into kube-system.
Names are unique per kind per namespace - dev and prod can both have web.
A Service in another namespace is reachable as web.prod.svc.cluster.local
(Day 2).
Warning
Deleting a namespace deletes everything in it - no confirmation, no undo.
Check kubectl config get-contexts first.