Namespace
A Namespace is a Kubernetes mechanism for dividing one cluster into isolated logical sections, so teams, projects, or environments can share the same infrastructure with separate names, access controls, and resource quotas. Namespaces do not isolate network traffic by themselves.
What namespaces give you
- Name scoping: two teams can each have a Service called
api. - RBAC scoping: grant a team rights only in its own namespace.
- Resource limits: attach ResourceQuotas and LimitRanges per namespace.
- Organisation: labels and policies apply per team or environment.
Default namespaces
| Namespace | Purpose |
|---|---|
| default | Where objects go if none is specified |
| kube-system | Kubernetes system components |
| kube-public | Publicly readable cluster data |
| kube-node-lease | Node heartbeat objects |
Work with namespaces
kubectl create namespace payments-teamkubectl get pods -n payments-teamkubectl config set-context --current --namespace=payments-teamCross-namespace access
A short name resolves only within the same namespace. Use the namespace in the name from elsewhere.
curl http://api-svc.backend-team.svc.cluster.local:8080What namespaces do not isolate
- Network traffic. Pods in different namespaces can talk by default.
- Nodes. All namespaces share the same nodes.
- Cluster-scoped resources such as Nodes, PersistentVolumes, and StorageClasses.
SecurityApply a default-deny NetworkPolicy to each new namespace and then allow only required flows. This needs a CNI that enforces policies.
TipLabel namespaces consistently, for example
teamandenvironment, so monitoring, cost reports, and policies can select them.
Common MistakeRunning production workloads in
default. A carelesskubectl deletewithout-ncan then affect everything.
Frequently Asked Questions
Does a Namespace provide network isolation?
No. By default any pod can reach any other pod across namespaces. NetworkPolicies, enforced by a supporting CNI, provide the isolation.
How should I structure namespaces?
Commonly one per team or per environment. A namespace per microservice multiplies policies, quotas, and bindings without much benefit.
Which resources are not namespaced?
Nodes, PersistentVolumes, StorageClasses, ClusterRoles, and namespaces themselves are cluster-scoped.