Kubernetes
ResourceQuota
Namespace
Resource Management
Cloud Computing

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.

Practice system design

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
Course
Beginner
27 lessons
10 hours
System Design Fundamentals

Build a strong foundation in designing scalable, reliable distributed systems.

View the course
Track 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.

Practice system design

All Rights Reserved.