What are Kubernetes Namespaces?
· Category: Kubernetes
Short answer
Kubernetes Namespaces partition a cluster into virtual sub-clusters. They provide a scope for resource names, access control, and resource quotas, enabling multiple teams or projects to share a cluster safely.
How it works
Objects created in one Namespace are isolated from other Namespaces by name. You can set resource quotas and RBAC policies per Namespace. Some resources like Nodes and PersistentVolumes are cluster-scoped and not namespaced.
Example
kubectl create namespace development
kubectl create namespace production
kubectl run nginx --image=nginx -n development
Set a context to a namespace:
kubectl config set-context --current --namespace=production
Why it matters
Namespaces reduce the risk of naming collisions and allow fine-grained access control. They are essential for multi-tenant clusters where different teams or environments share the same infrastructure.
Common issues
- Network policies are required for true network isolation between Namespaces.
- Resource quotas can unexpectedly block deployments if limits are too low.
- Some cluster-level resources cannot be scoped to a Namespace.