LimitRanges and ResourceQuotas

Intermediate · 20 min

Namespace guardrails enforced at admission: LimitRange defaults and bounds per container, ResourceQuota budgets per namespace, scopes, and their errors.

Before thisRequests, limits and QoS classesLabels, selectors, annotations and namespaces

TechOps Tutorials · 22 min · from 1:43

LimitRanges and ResourceQuotas

The player loads from youtube-nocookie.com when you press play. Nothing reaches YouTube before that.

Taught by TechOps TutorialsReport a problem with this video
Not started
Set this lesson's status

What you'll learn

  • A LimitRange works per container or Pod in one namespace: it fills in default requests and limits, and rejects values outside min, max or a limit-to-request ratio.
  • A ResourceQuota is a budget for the whole namespace: total requests and limits, storage, and object counts such as Pods, Services of type LoadBalancer or any resource via count/<resource>.
  • Both are admission plugins, so they act when an object is created. Existing Pods aren't touched when you add or change them.
  • A quota on requests.cpu or limits.memory makes those fields mandatory in the namespace. Pair the quota with a LimitRange so Pods without them get defaults instead of being rejected.
  • Quota failures on Pods made by controllers don't show on the Deployment. Look at the ReplicaSet's ReplicaFailure condition and events.

Requests are optional, and that’s the problem

The previous lesson showed that the scheduler only knows what Pods request. In a shared cluster, that’s an honour system. One team forgets requests and their BestEffort Pods pack nodes until things fall over. Another asks for 64 CPUs per replica “to be safe” and starves everyone else. A third creates 40 LoadBalancer Services and the cloud bill jumps.

Kubernetes has two namespace-scoped objects for this, both enforced by admission plugins in the API server. A LimitRange is a rule for each container: give it sane defaults and keep it within bounds. A ResourceQuota is a budget for the namespace as a whole. Think of a company expense policy: per-item rules (“no single purchase over 2,000”) and a department budget (“40,000 a quarter in total”).

LimitRange: defaults and bounds

apiVersion: v1
kind: LimitRange
metadata: {name: defaults, namespace: team-b}
spec:
  limits:
  - type: Container
    defaultRequest: {cpu: 100m, memory: 128Mi}
    default: {cpu: 500m, memory: 256Mi}
    max: {cpu: "2", memory: 2Gi}
    min: {cpu: 50m, memory: 64Mi}
    maxLimitRequestRatio: {memory: "2"}

defaultRequest and default fill in missing requests and limits. A plain kubectl run plain --image=nginx in that namespace came out with requests 100m/128Mi and limits 500m/256Mi, QoS Burstable, and an annotation saying what changed: LimitRanger plugin set: cpu, memory request for container plain; cpu, memory limit for container plain.

min, max and maxLimitRequestRatio reject. A container asking for 128Mi with a 1Gi limit was refused: memory max limit to request ratio per Container is 2, but provided ratio is 8.000000. The ratio is useful against heavy memory overcommit, where Pods request little, burst far and get OOM-killed together.

Defaults can also collide with what the user did set. A Pod requesting 3 CPUs with no limit got the default limit of 500m and was then invalid: must be less than or equal to cpu limit of 500m. Users see the error without seeing the LimitRange that caused it, so check kubectl get limitrange when a Pod is rejected for no obvious reason.

type: Pod bounds the sum across a Pod’s containers, and type: PersistentVolumeClaim bounds claim sizes.

ResourceQuota: the namespace budget

apiVersion: v1
kind: ResourceQuota
metadata: {name: team-b, namespace: team-b}
spec:
  hard:
    requests.cpu: "2"
    requests.memory: 2Gi
    limits.memory: 4Gi
    pods: "10"
    count/deployments.apps: "5"
    persistentvolumeclaims: "4"
    requests.storage: 100Gi
    services.loadbalancers: "1"

A quota can cap compute (requests.*, limits.*), storage (total requests.storage, claim counts, per-StorageClass amounts) and the number of objects of any kind via count/<resource>.<group>. The quota controller keeps status.used current, and admission refuses anything that would push past hard.

We scaled a Deployment to 12 replicas in that namespace. kubectl reported success, the Deployment stuck at UP-TO-DATE 9, and the real error was on the ReplicaSet’s ReplicaFailure condition:

pods "web-689b9bdbdd-ck6rt" is forbidden: exceeded quota: team-b, requested: pods=1, used: pods=10, limited: pods=10

kubectl describe quota showed why, with pods 10/10 next to requests.cpu 1/2 and limits.memory 2560Mi/4Gi. Quota errors on Pods created by controllers never appear on the Deployment itself, so that’s the first place people look and the last place the answer is.

Quotas make fields mandatory

When a quota tracks a compute resource, every new Pod must declare it, or it couldn’t be counted. In a namespace with a quota on requests.cpu and limits.memory and no LimitRange, a plain Pod was refused:

pods "nores" is forbidden: failed quota: q: must specify limits.memory for: nores; requests.cpu for: nores

That’s why the two objects usually come as a pair. The LimitRange plugin runs before the quota plugin in the admission chain, so defaults are filled in before quota checks.

Scopes

A quota can apply only to some Pods. Scopes include BestEffort, NotBestEffort, Terminating/NotTerminating (by activeDeadlineSeconds) and, most usefully, PriorityClass through scopeSelector. This one forbids a tenant from using a system priority:

spec:
  hard: {pods: "0"}
  scopeSelector:
    matchExpressions:
    - {scopeName: PriorityClass, operator: In, values: [system-cluster-critical]}

A Pod with priorityClassName: system-cluster-critical was refused with exceeded quota: no-critical. That matters because priority drives preemption: a tenant with a high priority class can evict everyone else’s Pods.

Limits of the approach

Both objects act at admission only. Change a quota or LimitRange and existing Pods aren’t touched. A quota can be set below current usage: nothing is evicted, new objects are just refused until usage drops. And quotas count requests, not real use, so they keep teams honest about reservations rather than consumption. For multi-tenant clusters they’re one layer, alongside RBAC, NetworkPolicy and Pod Security (see multi-tenancy).

About the video

The embed is a 22-minute clip, 1:43 to 23:28, of TechOps Tutorials’ “Why Kubernetes Blocks Your Pods – ResourceQuota and LimitRange Explained”, May 2026. The clip covers the noisy-neighbour problem, why default Kubernetes isn’t enough, ResourceQuota as a namespace budget, LimitRange defaults and boundaries, object quotas, admin and developer controls, and demos of quota rejection, scaled Deployments hitting hard limits, and LimitRange auto-injection. It doesn’t cover scopes or the ratio rule. Judged from chapters, since transcripts can’t be fetched here, and from its “English (US) original” audio track. It’s a small channel. Techi Nik’s 8-minute LimitRange video in deeper is the short version.

What was run: against a local v1.37.3 API server, we created the LimitRange and ResourceQuota above and saw defaults injected with the limit-ranger annotation, the request-above-default-limit and ratio rejections, a 12-replica Deployment stop at the 10-Pod quota with the error on its ReplicaSet, the must specify rejection in a quota-only namespace, and the PriorityClass-scoped quota refuse a Pod. All of it is real admission and quota-controller behaviour. No Pods ran, checked 2026-11-29.

Where this fits

With requests in place, the scheduler has the numbers it needs. Next: how the scheduler places Pods.

Check yourself

  1. 01A namespace has a LimitRange with default cpu limit 500m and no defaultRequest. Someone creates a Pod requesting 3 CPUs with no limit. What happens?

    It's rejected. The LimitRange fills in a limit of 500m, and a request above its limit is invalid ('must be less than or equal to cpu limit of 500m'). Defaults can collide with what the user did set, so set max as well and choose defaults with care.

  2. 02kubectl scale deployment web --replicas=12 returns success, but only 9 Pods exist and the Deployment never becomes available. Where's the error?

    On the ReplicaSet. The Deployment was updated fine; its ReplicaSet's Pod creates were rejected by the ResourceQuota (exceeded quota ... pods=10). kubectl describe rs or the namespace events show it, and kubectl describe quota shows used against hard.

  3. 03After adding a ResourceQuota with requests.cpu, every new Pod without resources fails with 'must specify requests.cpu'. Why, and what's the usual fix?

    When a quota tracks a compute resource, every new Pod must declare it so it can be counted. Add a LimitRange with defaultRequest and default so the admission chain fills them in before quota checks.

  4. 04How would you stop a tenant namespace from creating Pods with the system-cluster-critical priority?

    A ResourceQuota with a PriorityClass scopeSelector for system-cluster-critical and hard pods 0. Pods in that priority class count against it and are refused; other Pods are unaffected.

Go deeper

Notes

Private to you

Esc
↑↓ navigate↵ open? shortcuts

Keyboard shortcuts

Press Esc to close

Anywhere

⌘K
Search and commands
/
Search
?
This sheet
Esc
Close

Reading a lesson

J
Next lesson
K
Previous lesson
B
Bookmark