What happens if more than one ResourceQuota is enabled per namespace?
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Overview of ResourceQuota in Kubernetes
In Kubernetes, a `ResourceQuota` is used to enforce limits on the resource consumption within a particular namespace. It ensures fair usage of resources by restricting the aggregate resource consumption across all objects in a namespace. Administrators can define quotas on various resources, such as CPU, memory, storage, and the number of objects (like pods, services, etc.).
Enabling Multiple ResourceQuotas per Namespace
As of Kubernetes v1.15, you can define multiple `ResourceQuota` objects within a single namespace. This enhancement allows for more granular control over resource usage, enabling better design of multi-team environments and layered policy enforcement.
How Does It Work?
When multiple `ResourceQuota` objects are present in a namespace, Kubernetes aggregates their effects to determine if an operation violates any of the quotas.
Key Principles:
- ResourceQuota objects are additive. The total allowed usage is the sum of all `ResourceQuota` objects defining a particular resource.
- `ResourceQuota` enforcement is based on the current usage, verified at the namespace level whenever a resource request is made.
- If any `ResourceQuota` constraint is exceeded, the request is denied.
Illustrative Example
Consider a scenario where you have two `ResourceQuota` objects in a namespace, each specifying constraints on different resource kinds.
- The total CPU request limit is 2 cores, and total memory request limit is 4GiB from `compute-resources`.
- The namespace can have up to 5 PVCs (Persistent Volume Claims) and a total of 100GiB storage requests from `storage-resources`.
- Aggregation: Kubernetes will sum up quota values which target the same resource kind (e.g., compute resources).
- Independence: Quotas targeting different resource types are independently enforced.
- Multi-Team Environments: Differentiating resource limits based on teams or applications within a single namespace.
- Development vs. Production: Enforcing stricter limits for production workloads while allowing more relaxed quotas for development.
- Burst Workloads: Managing bursty workloads by having baseline and maximum quotas.
- Operational Overhead: Tracking and managing multiple quota objects can become intricate, necessitating tools or automation.
- Error Proneness: Without careful planning, conflicting or redundant quotas might inadvertently restrict necessary resource allocation.
Related reading
- what happens if the java heap memory limits is different than the pod resource limits in kubernetes?
- What happens to persistent volume if the StatefulSet got deleted and re-created?
- What happens when the Kubernetes master fails?
- What is a headless service, what does it do/accomplish, and what are some legitimate use cases for it?
- What happens when I reboot an EC2 instance?
- What is a dangling image and what is an unused image?
- What is a Kubernetes Manifest?
- What is a rollout in Kubernetes?

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.