Skip to main content

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.
flowchart TD C["mumbai-prod-cluster"] --> A["payments-team"] C --> B["orders-team"] C --> M["monitoring"] C --> S["kube-system"] classDef cluster fill:#475569,color:#ffffff classDef ns fill:#DBEAFE,color:#1E293B classDef sys fill:#FFEDD5,color:#1E293B class C cluster class A,B,M ns class S sys

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

Bash
kubectl create namespace payments-team
kubectl get pods -n payments-team
kubectl config set-context --current --namespace=payments-team

Cross-namespace access

A short name resolves only within the same namespace. Use the namespace in the name from elsewhere.

Bash
curl http://api-svc.backend-team.svc.cluster.local:8080

What 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.
Security

Apply a default-deny NetworkPolicy to each new namespace and then allow only required flows. This needs a CNI that enforces policies.

Tip

Label namespaces consistently, for example team and environment, so monitoring, cost reports, and policies can select them.

Common Mistake

Running production workloads in default. A careless kubectl delete without -n can 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.

Found a mistake, an outdated step or a broken link?