Stand up a safe multi-tenant namespace
When several teams share a cluster, an unbounded namespace can starve everyone else by scheduling too many pods or oversized containers. This builder generates the three objects that fence off a namespace: the Namespace itself, a ResourceQuota capping aggregate usage, and a LimitRange providing sensible per-container defaults.
How it works
The ResourceQuota sets hard ceilings on the sum of requests.cpu, requests.memory, limits.cpu, limits.memory, and the pod count across the whole namespace. Kubernetes enforces these at admission time — any request that would push the namespace over a cap is rejected.
A quota that limits limits.cpu/limits.memory forces every container to declare those values. The LimitRange fills the gap: it injects default and defaultRequest values into containers that omit them, and sets per-container max ceilings. Together they guarantee that every workload is accounted for and the quota math always has the numbers it needs.
Tips and notes
- Keep
defaultRequestmodest — it is the floor each container reserves and counts against the quota even when idle. - Set the LimitRange
maxto your largest sane container so a single workload cannot consume the entire namespace. - Add a
teamlabel to the namespace for cost attribution and to target it with network policies or RBAC. - Apply all three documents together; the LimitRange should exist before workloads are deployed so defaults take effect.