Sub topic 14
Namespaces as a tenancy boundary: what they do and do not give you
This chapter assumes you know Pods, Services, and kubectl, and that you have met ResourceQuota, LimitRange, RBAC, NetworkPolicy, and Pod Security Admission from earlier chapters. Here you combine them and see where the combination stops working.
A namespace is a scope, not a wall
A namespace groups objects under a name. It gives you name uniqueness, a target for access rules, and a target for quotas. A new namespace has none of the following by default:
- Network isolation. Any Pod can reach any other Pod by IP, in any namespace.
- Resource caps. Pods compete for the same nodes.
- Access limits. These exist only once you write Roles and RoleBindings.
- Pod privilege limits. These exist only once you set Pod Security Admission labels.
Each control is a separate object that you create and keep up to date.
Building a team boundary
A usable per-team namespace combines four controls.
| Concern | Object | Effect |
|---|---|---|
| Compute consumption | ResourceQuota plus LimitRange | Caps the namespace total and gives containers defaults |
| API access | Role and RoleBinding | Limits users to objects in this namespace |
| Network traffic | NetworkPolicy | Denies ingress, then allows listed sources |
| Pod privileges | Pod Security Admission labels | Rejects Pods that break the chosen standard |
Check the access rule rather than assuming it works. With the pod-reader Role from the RBAC chapter bound to jane, ask the API server:
kubectl auth can-i list pods --namespace team-a --as jane
kubectl auth can-i list pods --namespace team-b --as janeThe first command should print yes and the second no.
What namespaces do not isolate
Several resources and mechanisms sit outside any namespace:
- Nodes, PersistentVolumes, StorageClasses, ClusterRoles, and CustomResourceDefinitions are cluster-scoped. One tenant's CRD or admission webhook affects everyone.
- Pods from different tenants share nodes and the node kernel. A container escape or kernel bug crosses namespace lines.
- All tenants share one API server and one etcd. A tenant that floods the API with requests can slow the others. Quotas limit object counts, not request rates.
- Service DNS names resolve from any namespace. Without a NetworkPolicy,
orders.team-b.svc.cluster.localis reachable fromteam-a. - A user with permission to list namespaces sees every namespace name, because Namespace is cluster-scoped.
Two failures are easy to miss. A NetworkPolicy does nothing if the cluster's network plugin does not enforce it, and the API server accepts the object without warning. A ResourceQuota on CPU or memory also rejects Pods that omit requests, unless a LimitRange supplies defaults.
Choosing a boundary
Pick the boundary that matches how far you trust the people deploying into it.
| Situation | Reasonable choice |
|---|---|
| Teams in one company who cooperate | Namespaces with all four controls |
| Same, with stricter workload separation | Namespaces, plus dedicated node pools using taints and node selectors |
| Untrusted code or customers who need their own CRDs | Separate clusters, or virtual clusters |
| Hostile workloads on shared nodes | Separate clusters, or sandboxed runtimes such as gVisor or Kata Containers |
Namespaces suit soft multi-tenancy, where tenants are not malicious but you want to prevent accidents and noisy neighbors. Hard multi-tenancy needs isolation below the namespace layer.
Exercise
Your cluster has namespaces team-a and team-b. You applied a default-deny ingress NetworkPolicy in team-a, but a Pod in team-b can still reach a Pod in team-a. Give two likely causes.
Show answer
First, the cluster's network plugin may not enforce NetworkPolicy, so the object is stored but ignored. Second, another NetworkPolicy in team-a may allow the traffic, for example one that selects team-b through a namespaceSelector. Policies are additive, so any matching allow rule permits the connection.
Exercise
Name two things a tenant in a namespace can still affect for other tenants, even with quota, RBAC, NetworkPolicy, and Pod Security Admission in place.
Show answer
Any two of these: the node kernel (shared by all Pods on a node), API server and etcd load, and cluster-scoped objects such as CRDs and admission webhooks.