Introduction

Kubernetes ResourceQuota and LimitRange are the two admission guardrails that keep a shared namespace fair: one caps the namespace total, the other governs each container. This guide shows how to set both, read the errors they produce, and roll them out without breaking running teams.

Consider an illustrative composite scenario, not a named outage. Three teams share one cluster, each in its own namespace. A batch job in one namespace scales to hundreds of Pods overnight, requests most of the free CPU, and leaves a production service unable to schedule new replicas during a morning deploy. No node failed. The cluster simply had no rule that said how much of the total each team was allowed to claim.

5-minute takeaway. Apply a LimitRange first so every container gets sane default requests and limits. Then apply a ResourceQuota that caps total requests, total limits, storage and object counts for the namespace. Check usage with kubectl describe resourcequota, leave headroom for rolling updates, and alert before usage reaches the hard limit. That order prevents the most common self-inflicted outage in this area: a quota that rejects every Pod that omits resource fields.

This is lesson 12 in the Kubernetes Roadmap Series, in Module 6 on requests, limits and quotas. The previous lesson, External Secrets Operator on Kubernetes, covered syncing secrets from Vault and AWS Secrets Manager. The next lesson covers QoS classes and eviction order; find it in the Kubernetes roadmap, Module 6. If Pods, Deployments and Services are still fuzzy, read Kubernetes Concepts Explained first.


1. Kubernetes ResourceQuota and LimitRange: what each object owns

Kubernetes ResourceQuota and LimitRange answer different questions. ResourceQuota asks whether the namespace as a whole has used more than its allocation. LimitRange asks whether one container, Pod or claim is reasonably sized, and what values to fill in when a developer declared nothing.

ResourceQuota is namespace-scoped and aggregate. Its spec.hard map sets ceilings such as total CPU requests, total memory limits, total storage claimed, or a maximum number of Pods. When a create or update request would push the namespace past a ceiling, the API server rejects that request. Pods already running keep running, because quota is checked at admission time, not enforced by killing workloads later.

LimitRange is also namespace-scoped, but it works one object at a time. It can inject default requests and limits into containers that specify none, reject containers below a minimum or above a maximum, cap how far a limit may sit above its request, and bound the size of a single Pod or PersistentVolumeClaim. It is the only one of the two objects that can change your spec, because its defaults are written into the Pod at admission.

You need both. A quota without a LimitRange rejects every Pod that omits the capped request or limit fields, which turns a routine deploy into a wall of forbidden errors. A LimitRange without a quota keeps each container reasonable but lets a team run ten thousand reasonable containers. The pair gives you a per-object floor and ceiling plus a namespace budget, and each half covers the failure mode of the other.


2. Kubernetes ResourceQuota and LimitRange: requests versus limits at admission

Kubernetes ResourceQuota and LimitRange both act at admission, before anything reaches etcd or the scheduler, and the order they run in explains most surprises. LimitRange defaults are applied first, then its bounds are validated, and only then does ResourceQuota add up the namespace total.

Requests and limits play different roles in that accounting. A request is the amount the scheduler reserves when placing a Pod, and quota sums requests to decide whether the namespace has promised more than its budget. A limit is the ceiling a container may burst to on the node, and quota can sum limits separately to bound total burst. That is why spec.hard carries four compute keys: requests.cpu, requests.memory, limits.cpu and limits.memory. The plain keys cpu and memory are aliases for the requests keys, not for limits, which catches people who set cpu and expect a limit cap.

The sharp edge is mandatory fields. Once a quota names requests.cpu, every container in the namespace must declare a CPU request, because the quota accountant cannot add a value that does not exist. The same holds for each capped field. A Pod that omits the field is rejected with a forbidden error naming the missing field, even when the namespace has plenty of quota left. This is correct behaviour with a painful rollout: the day the quota lands, every manifest without resources breaks. A LimitRange with defaults removes that pain by filling the fields before quota counts them.

Admission rejection is not scheduling failure, and telling them apart saves hours. A quota or LimitRange rejection happens before the Pod object exists, so you see the error in kubectl apply output or in FailedCreate events on the owning ReplicaSet or Job. There is no Pod to describe. A scheduling failure happens after admission accepts the Pod, which then sits in Pending with FailedScheduling events. If the Pod does not exist at all, look at admission. If it exists and waits, look at the scheduler.


3. Kubernetes ResourceQuota and LimitRange: hard limits for compute

Kubernetes ResourceQuota and LimitRange start with compute ceilings in spec.hard: total CPU and memory requests, total CPU and memory limits, and extended resources such as GPUs. Set requests quotas from measured demand, and set limits quotas higher so containers keep honest burst room.

A typical compute quota for a team namespace looks like this:

yaml
apiVersion: v1
kind: ResourceQuota
metadata:
  name: team-quota
  namespace: team-payments
spec:
  hard:
    requests.cpu: "20"
    requests.memory: 40Gi
    limits.cpu: "40"
    limits.memory: 80Gi
    pods: "100"

Read the four compute lines as two budgets. The requests budget is what the namespace may promise the scheduler. The limits budget is what it may burst to. Keeping limits at roughly twice requests is a common starting point: enough burst for spikes, not so much that every container can claim four times its reservation at once. Tune both from real usage data rather than copying numbers, because a namespace of small APIs and a namespace of batch workers need different shapes.

Extended resources follow one special rule. For resources such as nvidia.com/gpu, only the requests form is allowed in quota, written as requests.nvidia.com/gpu, because overcommit is not permitted for devices that cannot be shared by time-slicing in the same way CPU can. HugePages requests can also be capped per size with keys such as hugepages-2Mi. Most teams never need those keys, but GPU namespaces depend on them to stop one team from reserving every accelerator in the cluster.

Quota counts what Pods declare, not what they actually use. A namespace can sit at its requests ceiling while nodes idle, if teams overstate requests. That gap is a sizing problem, not a quota bug, and it is why quota work pairs naturally with right-sizing reviews. The HPA vs VPA guide covers the adjacent question of adjusting replica count versus Pod size once the budget exists.


4. Kubernetes ResourceQuota and LimitRange: storage and object-count quotas

Kubernetes ResourceQuota and LimitRange also cap storage and object counts, and these keys prevent failures that compute quotas never see. A runaway controller creating Secrets, or a team claiming terabytes of fast storage, can hurt a cluster while CPU graphs look calm.

Storage quota uses three forms. requests.storage caps the total storage claimed by PersistentVolumeClaims in the namespace. persistentvolumeclaims caps how many claims may exist. A per-StorageClass key such as fast-ssd.storageclass.storage.k8s.io/requests.storage caps claims against one class, which matters when one class is expensive or capacity-limited. A matching per-class claim-count key exists as well. Set the total and the expensive-class caps together, so a team cannot spend the whole storage budget on the premium tier by accident.

Object-count quotas cover the built-in kinds directly: pods, services, secrets, configmaps, replicationcontrollers, plus services.loadbalancers and services.nodeports for the costly Service types. For anything else, the generic form is count/<resource>.<group>, for example count/deployments.apps or count/cronjobs.batch. The pods count covers non-terminal Pods, meaning Pending and Running, so completed Job Pods stop counting once they finish.

These caps earn their place during incidents. A buggy operator in a loop can create thousands of ConfigMaps and put real pressure on etcd and the API server. A count quota turns that incident into a bounded set of forbidden errors in one namespace instead of a cluster-wide slowdown. LoadBalancer counts matter for cost as much as stability, because each one usually provisions a paid cloud load balancer. Review object counts whenever you review compute, because leaks show up in counts first.


5. Kubernetes ResourceQuota and LimitRange: scopes and scope selectors

Kubernetes ResourceQuota and LimitRange support scopes so one namespace can carry different rules for different workload classes. A scope narrows which Pods a quota counts, which lets you cap batch work tightly while leaving production services more room inside the same namespace budget.

The built-in scopes come in pairs. Terminating matches Pods with an active deadline, which means Jobs, while NotTerminating matches everything else. BestEffort matches Pods with no requests or limits anywhere, and NotBestEffort matches Pods that set at least one. PriorityClass matches Pods by priority class name through a scope selector. A quota that uses BestEffort scope may only cap the pods count, because BestEffort Pods declare no compute to sum.

Scope selectors give finer control than the coarse scope names. A selector can match on priority class with operators such as In, NotIn, Exists and DoesNotExist. For example, a quota with a selector for a low priority class can cap batch Pods at a small slice of the namespace, while an unscoped quota caps the namespace total. A Pod must fit under every quota whose scope it matches, so overlapping quotas stack rather than replace each other.

Scopes are powerful and easy to misread during an incident. When a rejection names a quota you did not write, list every quota in the namespace and read each scopes and scopeSelector block before changing numbers. Most scope confusion comes from a second quota added for batch or BestEffort Pods that nobody remembered. Keep the number of quotas per namespace small, name them after the class they govern, and document why each one exists in the same repo that applies it.


6. Kubernetes ResourceQuota and LimitRange: defaults that keep deploys working

Kubernetes ResourceQuota and LimitRange meet in the LimitRange defaults, the fields that fill in requests and limits a container omitted. defaultRequest sets the request, default sets the limit, and together they keep quota-governed namespaces deployable for teams that forget resource fields in their manifests.

A container-level LimitRange for a team namespace looks like this:

yaml
apiVersion: v1
kind: LimitRange
metadata:
  name: team-limits
  namespace: team-payments
spec:
  limits:
    - type: Container
      default:
        cpu: 500m
        memory: 512Mi
      defaultRequest:
        cpu: 100m
        memory: 128Mi
      min:
        cpu: 50m
        memory: 64Mi
      max:
        cpu: "4"
        memory: 8Gi
      maxLimitRequestRatio:
        cpu: "10"
        memory: "4"

The naming traps people: default means default limits, not default everything. A container that declares no resources receives the defaultRequest values as requests and the default values as limits. A container that declares only a limit keeps that limit and receives the default request, and the reverse also holds. Defaults apply only at admission, so Pods already running keep their current values when you change the LimitRange. Rolling a Deployment is how existing Pods pick up new defaults.

Choose defaults from the smallest honest workload in the namespace, not from the average. Defaults that are too large waste scheduler capacity on every Pod that forgets resources, and defaults multiplied by expected Pod count must stay under the namespace quota or the defaults themselves exhaust it. One hundred Pods at a 500m default CPU limit is 50 CPU of limits quota consumed by omission. Small defaults with explicit values on real workloads is the safer shape.

Defaults also decide quality of service for careless Pods. A Pod with no requests or limits is BestEffort and first in line for eviction under node pressure. A defaultRequest guarantees no Pod in the namespace is accidentally BestEffort, which removes a whole class of surprise evictions. The next lesson in this module covers QoS classes and eviction order in full.


7. Kubernetes ResourceQuota and LimitRange: min, max and burst ratio bounds

Kubernetes ResourceQuota and LimitRange bounds reject unreasonable objects at admission: min and max set the permitted range per container, Pod or claim, and maxLimitRequestRatio caps how far a limit may sit above its request, which keeps burst behaviour honest on shared nodes.

The min bound stops containers so small they waste scheduling overhead and invite throttling or memory kills. The max bound stops one container from claiming half a node by typo, such as a memory limit typed in Gi when Mi was intended. Bounds exist for three types: Container applies per container, Pod applies to the sum across a Pod, and PersistentVolumeClaim bounds claim size with min and max storage values. A claim below the minimum or above the maximum is rejected when created.

The ratio bound is underused and valuable. A container requesting 100m CPU with a 4-core limit looks cheap to the scheduler and behaves expensively on the node, because it can burst to forty times its reservation while neighbours planned around the small request. maxLimitRequestRatio with a CPU value of 10 means the limit may be at most ten times the request. Memory ratios deserve tighter values, often 2 to 4, because memory cannot be throttled the way CPU can. A container that exceeds its memory limit is killed, and the fix path for those kills lives in Kubernetes OOMKilled: Fix Exit Code 137, which covers sizing limits from measurements rather than guessing.

Bounds and quota must agree with each other. A container max of 4 CPU inside a namespace quota of 2 CPU requests means a max-sized container can never be admitted, which is legal but confusing. Set bounds from the largest legitimate workload, set quota from the namespace budget, and check the pair together in review. When a rejection says a value is below the minimum or above the maximum, the LimitRange is speaking, not the quota, and the fix is the container spec or the bound, not the namespace budget.


8. Kubernetes ResourceQuota and LimitRange: choosing the right guardrail

Kubernetes ResourceQuota and LimitRange solve different problems, so pick the guardrail that matches the failure you fear. The table below maps common multi-team risks to the object and field that controls each one, so design reviews start from the failure mode instead of from habit.

Risk Guardrail Field to set
One team promises more CPU than its share ResourceQuota requests.cpu, requests.memory
Burst capacity crowds out neighbours ResourceQuota limits.cpu, limits.memory
Pods arrive with no resources at all LimitRange defaultRequest, default
One container claims half a node LimitRange max per Container
Tiny containers thrash and get killed LimitRange min per Container
Limits sit far above requests LimitRange maxLimitRequestRatio
Premium storage class drains the budget ResourceQuota per-StorageClass storage key
A controller leaks Secrets or ConfigMaps ResourceQuota secrets, configmaps, count/ keys
Batch work starves production services ResourceQuota Terminating scope or PriorityClass selector
One claim requests an absurd volume LimitRange max storage per PersistentVolumeClaim

Read the table as a design checklist, not a menu where you pick one row. A shared namespace normally needs the first six rows together: quota for totals, defaults for omissions, bounds for outliers. Storage and count rows join when the namespace runs stateful workloads or operators. Scope rows join when batch and production share a namespace, though separate namespaces per workload class stay easier to reason about.

Two combinations deserve a warning. Quota on limits without quota on requests lets a team promise little and burst a lot, which defeats the scheduler accounting the requests budget exists to protect. Defaults without bounds let a typo through at any size, because defaults only fill empty fields and never correct stated ones. The Kubernetes Best Practices guide places these guardrails in a wider production checklist, and this lesson supplies the namespace-level detail behind that checklist.


9. Kubernetes ResourceQuota and LimitRange: rollout order for multi-team namespaces

Kubernetes ResourceQuota and LimitRange should roll out in a fixed order: LimitRange first, observation second, quota third. Reversing that order is how platform teams break every deploy in a namespace on the day governance arrives, usually during the first release that follows the change.

Start by inventorying what the namespace already declares. List Pods with their requests and limits, and sum them per resource. That sum is your starting budget evidence. If half the Pods declare nothing, defaults will change the totals the moment they land, so measure again after the LimitRange has been live through one full deploy cycle of the main workloads.

Apply the LimitRange with conservative defaults and generous bounds. Generous bounds matter at this stage because the goal is to fill omissions, not to reject legitimate large workloads you have not catalogued yet. Watch admission rejections for a few days. Each rejection is either a workload that needs explicit resources or a bound that needs widening, and both are cheap to fix while no quota depends on the numbers.

Then apply the ResourceQuota with headroom above current usage. Headroom is not slack for its own sake: rolling updates temporarily run old and new Pods together, so a namespace at 95 percent of quota cannot complete a normal rollout with surge. Leave room for the largest Deployment to surge, or set surge to zero on tight namespaces and accept slower rollouts. Alert at a threshold such as 80 percent of hard for requests and storage, so the conversation about raising a budget happens before deploys start failing.

Manage both objects as code, in the same repo and review flow as the namespace itself. A tenant template that creates the namespace, LimitRange, ResourceQuota, RBAC and network policy together keeps every team on the same guardrail shape, with numbers adjusted per team. Quota changes then go through review like any other capacity change, and the reason for each number stays in commit history instead of in one engineer's memory. Keep the kubectl Master Guide nearby for the inspection commands used in the next section.


10. Kubernetes ResourceQuota and LimitRange: reading quota exceeded errors

Kubernetes ResourceQuota and LimitRange rejections carry precise messages, and reading them literally is the fastest path to a fix. The two messages you will meet most are exceeded quota and must specify, and they point at different objects, so the fix differs even though both arrive as forbidden errors.

An exceeded quota error names the quota, the resource that ran out, what the new object requested, what is already used, and the hard limit. It arrives as a 403 Forbidden response at admission. Existing Pods are untouched. The namespace budget for that resource is full, and the fix is to free budget, shrink the request, or raise the hard limit through review. Start with the quota itself:

bash
kubectl get resourcequota -n team-payments
kubectl describe resourcequota team-quota -n team-payments
kubectl get events -n team-payments --field-selector reason=FailedCreate

The describe output shows Used against Hard per resource. Any resource where Used equals Hard is the blocker. The FailedCreate events on the ReplicaSet or Job carry the same message when the rejection happened through a controller, which is the usual case: a Deployment looks healthy while its new ReplicaSet creates zero Pods, or a Job exists and silently retries without producing Pods.

A must specify error means the quota caps a field the Pod omitted, such as limits.cpu. The namespace may have budget to spare; the Pod is rejected because the field is missing, not because the total is full. The fix is a LimitRange default or an explicit value in the Pod spec. A third family of messages names the LimitRange directly, reporting a value below the minimum or above the maximum per container. Each message names its object, so let the error text choose your first command instead of guessing.

One subtlety catches people after a quota is lowered. If Used already exceeds a newly lowered Hard, nothing running is evicted, but every new create that needs that resource fails until usage drops below the limit. Lower quotas in steps, or during a window where the team can shed Pods, and tell the team before you apply the change.


11. Kubernetes ResourceQuota and LimitRange: troubleshooting matrix

Kubernetes ResourceQuota and LimitRange failures repeat in a small set of patterns. Match the symptom to the row, run the first check, and apply the fix that row names before changing any numbers, because raising a budget rarely fixes a bounds or template problem.

Symptom Likely cause First check Fix
Apply fails with exceeded quota Namespace budget full for one resource kubectl describe resourcequota Used vs Hard Free budget, shrink requests, or raise Hard
Apply fails with must specify limits.cpu Quota caps a field the Pod omits Pod template resources block Add explicit values or LimitRange defaults
Deployment healthy, new ReplicaSet has zero Pods Quota blocks Pod creation through controller FailedCreate events on the ReplicaSet Same as exceeded quota; check surge headroom
Job exists but creates no Pods Quota rejection retried by Job controller kubectl describe job events Free budget or fix the Pod template
Rejection names minimum or maximum per Container LimitRange bound violated kubectl get limitrange -o yaml Fix container spec or widen the bound
Quota full while nodes sit idle Requests overstated versus real use Compare requests sum with actual usage Right-size requests from measurements
Rollout stalls halfway No surge headroom under quota ReplicaSet events plus quota slack Raise quota or set maxSurge to 0
Storage claim rejected Storage or per-class quota full, or claim outside LimitRange bounds Quota describe plus claim size Free claims, resize claim, or adjust caps
Rejection names an unknown quota Second scoped quota in the namespace List all quotas and their scopes Adjust the scoped quota or the workload class
Pods rejected after quota lowered Used already above new Hard Compare Used with Hard Shed Pods or raise Hard back in steps

Work the matrix in order of evidence, not instinct. The error message and the Used against Hard table identify the exhausted resource in seconds, and both are cheaper than reading Pod specs across a namespace. When the message is missing because events expired, the quota describe output still shows which resource sits at its ceiling.

Separate quota trouble from scheduling trouble before you change anything. If the Pod object exists and sits in Pending, admission already accepted it and the scheduler is the blocker, which points at node capacity, taints or affinity instead. Quota work on a scheduling problem wastes the incident. Confirm which layer rejected the work, then fix that layer.


12. Kubernetes ResourceQuota and LimitRange: final checklist

Kubernetes ResourceQuota and LimitRange are ready for a shared namespace when defaults, bounds and budgets agree with each other and with measured demand. Use this checklist before you call the guardrails done, and rerun it whenever a new team, workload class or storage tier joins the namespace.

  • LimitRange applied before ResourceQuota, with defaults sized from the smallest honest workload.
  • Every container receives requests and limits, explicitly or through defaults, so no Pod is accidentally BestEffort.
  • Requests quota set from measured demand with headroom for the largest rolling update surge.
  • Limits quota set above requests quota for honest burst, with maxLimitRequestRatio keeping the gap sane.
  • Storage capped in total and per expensive StorageClass, with claim count and claim size bounds set.
  • Object counts capped for Pods, Services, Secrets and ConfigMaps, plus count/ keys for leaky controllers.
  • Scoped quotas used only where batch and production truly share a namespace, each named for its class.
  • Alerts firing before usage reaches Hard, and quota changes reviewed as capacity changes in Git.

Two habits keep the guardrails honest after rollout. Review Used against Hard monthly, because a quota nobody reads becomes either a wall teams route around or a budget so loose it governs nothing. Right-size requests from measurements on the same cadence, since quota counts declared requests and stale declarations quietly shrink the usable cluster. When memory limits themselves are the problem, because containers keep dying at their ceiling, work the sizing method in Kubernetes OOMKilled: Fix Exit Code 137 rather than raising limits blindly.

Guardrails are a fairness tool, not a capacity strategy. A namespace quota cannot create nodes, and a tight quota on an undersized cluster only moves the queue. Pair these objects with cluster capacity planning and autoscaling decisions, and the namespace budget becomes what it should be: a clear, reviewed statement of how much of the shared cluster each team may claim. Continue to QoS classes and eviction order in the Kubernetes roadmap, Module 6.

Frequently Asked Questions

What is the difference between Kubernetes ResourceQuota and LimitRange?

Kubernetes ResourceQuota caps the total a namespace may consume, such as total CPU requests or total storage. LimitRange governs one object at a time: it sets default requests and limits for containers that declare none, and rejects containers, Pods or claims outside set bounds. Use both together.

Why does Kubernetes ResourceQuota and LimitRange reject a Pod that sets no requests?

Once a quota caps a field such as requests.cpu, every container must declare that field, because quota accounting cannot sum a missing value. The Pod is rejected even when budget remains. A LimitRange defaultRequest fills the field at admission, which is why defaults should land before the quota.

What does exceeded quota mean in Kubernetes ResourceQuota and LimitRange?

It means creating the object would push the namespace past a hard limit in spec.hard. The error names the quota, the exhausted resource, the requested amount, current usage and the hard limit. Running Pods are not killed. Free budget, shrink the request, or raise the hard limit.

Does Kubernetes ResourceQuota and LimitRange kill running Pods when a quota fills?

No. Both objects act at admission time, when objects are created or updated. A full quota rejects new creates and leaves running Pods alone. Even lowering a hard limit below current usage only blocks new work until usage falls; it does not evict anything by itself.

How do scopes work in Kubernetes ResourceQuota and LimitRange?

Scopes narrow which Pods a quota counts. Terminating matches Job Pods, NotTerminating matches the rest, BestEffort matches Pods with no requests or limits, and PriorityClass selectors match by priority class name. A Pod must fit under every quota whose scope it matches, so scoped quotas stack.

How do I cap storage with Kubernetes ResourceQuota and LimitRange?

Use requests.storage for total claimed storage, persistentvolumeclaims for claim count, and a per-StorageClass key such as fast-ssd.storageclass.storage.k8s.io/requests.storage for one class. Add a LimitRange entry of type PersistentVolumeClaim to bound the size of each single claim.

In what order should I roll out Kubernetes ResourceQuota and LimitRange?

Apply the LimitRange first with conservative defaults and generous bounds, watch admission rejections through one deploy cycle, then apply the ResourceQuota with headroom above current usage. Alert before usage reaches the hard limit, and manage both objects as reviewed code beside the namespace.

⚡ KUBERNETES SCENARIO INTERVIEW PREP

Preparing for Senior Platform & SRE Interviews

Practice real-world cluster triage, RBAC debugging, and pod scheduling scenarios in our Kubernetes scenario interview questions hub.

Explore Interview Scenarios →