Interview Prep/DevOps Fundamentals/Containers & Kubernetes basics

What is a namespace in Kubernetes, and how is it used?

BeginnerConceptContainers & Kubernetes basics
Answer

In one line: A namespace is a virtual partition inside a Kubernetes cluster that groups resources and separates teams, apps or environments, so they can share one cluster without getting in each other's way.

What namespaces give you:

  1. Organisation — group resources: payments, orders, monitoring.
  2. Name scoping — two teams can both have a Service called api in different namespaces.
  3. Access control — RBAC Roles and RoleBindings apply per namespace (the payments team can only manage the payments namespace).
  4. Resource quotas — limit total CPU, memory and object counts per namespace with ResourceQuota, and set defaults with LimitRange.
  5. Network isolation — NetworkPolicy rules can block traffic between namespaces.

Default namespaces:

  • default — where things go if you don't specify a namespace (avoid using it for real apps).
  • kube-system — Kubernetes system components (CoreDNS, kube-proxy).
  • kube-public and kube-node-lease.

Commands:

kubectl create namespace payments
kubectl get pods -n payments
kubectl config set-context --current --namespace=payments
kubectl get pods -A        # all namespaces

Service DNS across namespaces: orders.payments.svc.cluster.local (or simply orders.payments).

Common patterns:

  • Per team or per app namespaces in a shared cluster.
  • Per environment namespaces (dev, qa) for non-production — but production is usually in a separate cluster for stronger isolation.
  • Per pull request namespaces for preview environments.

Limits: namespaces are not a hard security boundary. Nodes, cluster-wide resources (like CRDs and ClusterRoles) and the kernel are shared. For strong isolation, use separate clusters or extra tools.

Tip for interviews: mention RBAC, quotas and NetworkPolicies per namespace, and that production usually gets its own cluster.

All DevOps Fundamentals questions

More on Containers & Kubernetes basics