StackPractices
intermediate By Mathias Paulenko

Kubernetes Resource Quotas Template

Template for defining Kubernetes resource quotas per namespace: compute and storage limits, object count quotas, LimitRange defaults, priority-scoped quotas, and monitoring for multi-tenant clusters.

Topics: devops

Overview

This template gives you a complete, copy-paste-ready quota setup for a namespace in a multi-tenant Kubernetes cluster: a ResourceQuota with sensible defaults, the LimitRange it depends on, four quota tiers you can adapt per team, priority-scoped quotas, and the Prometheus queries to watch them. The ready-to-apply manifests live in the companion repo.

Use it when you’re provisioning namespaces for teams and need to stop any one of them from starving the rest. Quotas are the capacity half of that story; for the availability half, pair this with a Pod Disruption Budget so voluntary disruptions (drains, upgrades) can’t take a service down either.

Everything below follows the upstream ResourceQuota and LimitRange semantics.


1. How Resource Quotas Work

A ResourceQuota is an admission-control object. When someone creates a resource in a namespace, the quota admission plugin checks whether the new object would push the namespace over any tracked limit. If it would, the API server rejects the request with a 403 Forbidden before the object ever reaches etcd.

Two consequences of that design are worth keeping in mind:

  • Quotas only gate new work. A pod that’s already running keeps running even if you later tighten the quota. Existing objects are never recounted against a smaller quota, and nothing gets evicted because of it.
  • The moment a quota tracks a resource, every new object must declare it. If your quota includes requests.cpu, a pod without CPU requests is rejected outright; there’s no “free” allocation. This is why a ResourceQuota almost always ships with a LimitRange (section 2), which injects the missing requests so ordinary workloads don’t fail.

Accounting rules that surprise people

  • Quotas count requests, not actual usage. A pod that requests 2 CPU and idles at 50m still occupies 2 CPU of namespace quota.
  • For pods with init containers, the effective request is the largest init-container request if it exceeds the sum of the app containers, a detail that trips people up when a data-loader init container is bigger than the app itself.
  • count/* quotas cap the number of API objects, not their size. count/pods stops pod sprawl; count/configmaps and count/secrets protect etcd from a team that treats the API as a blob store. Objects like ConfigMaps have a hard 1 MiB size limit each, but a namespace can hold thousands of them. Object-count quotas are how you bound that.
  • The used column in kubectl describe resourcequota is what the quota controller has already accounted. A FailedCreate event on a workload controller plus used equal to hard is the tell-tale sign of a quota-blocked rollout.
Pod admission flow with ResourceQuota and LimitRange: creation passes the quota check, gets rejected if it exceeds the limit, LimitRange injects missing requests and the pod is scheduled

1.1 Quota types

Quota typeWhat it limitsExample keys
Compute (requests)Sum of CPU/memory requests across podsrequests.cpu, requests.memory
Compute (limits)Sum of CPU/memory limits across podslimits.cpu, limits.memory
StorageTotal PVC storage requestedrequests.storage, persistentvolumeclaims
Object countNumber of API objectscount/pods, count/services, count/configmaps
Extended resourcesGPUs and other custom resourcesrequests.nvidia.com/gpu
Per storage classPVC storage per StorageClassfast.storageclass.storage.k8s.io/requests.storage

There’s no native network quota; bandwidth and egress controls live in your CNI, not in ResourceQuota.

1.2 Namespace quota template

This is the standard-tier quota used throughout the template. Each group of keys is explained after the manifest.

apiVersion: v1
kind: ResourceQuota
metadata:
  name: team-payments-quota
  namespace: team-payments
  labels:
    app.kubernetes.io/managed-by: platform-team
    quota-tier: standard
spec:
  hard:
    # Compute resources — requests
    requests.cpu: "10"
    requests.memory: 20Gi

    # Compute resources — limits
    limits.cpu: "20"
    limits.memory: 40Gi

    # Storage
    requests.storage: 100Gi
    persistentvolumeclaims: "10"

    # Object counts
    count/pods: "50"
    count/services: "10"
    count/configmaps: "20"
    count/secrets: "20"
    count/deployments.apps: "10"
    count/statefulsets.apps: "5"
    count/jobs.batch: "20"
    count/cronjobs.batch: "10"
    count/ingresses.networking.k8s.io: "5"

    # Extended resources
    # requests.nvidia.com/gpu: "2"

A few notes on what’s in there:

  • Requests quotas first. requests.cpu: "10" means the sum of CPU requests across all pods in the namespace can’t exceed 10 cores. Tracking limits (limits.cpu) too bounds the burst ceiling, but many clusters skip it: CPU limits are what trigger throttling, and plenty of teams deliberately run limitRange defaults without per-pod limits (see the FAQ).
  • Storage quotas pair two things: requests.storage caps total gigabytes, persistentvolumeclaims caps how many PVCs exist. You need both: ten 1 Gi claims and one 10 Gi claim look very different to your storage provisioner.
  • Object counts are cheap insurance. count/services prevents an accidental LoadBalancer-per-namespace explosion (each one costs money on cloud providers). count/configmaps and count/secrets protect etcd.
  • Don’t forget job controllers. count/jobs.batch and count/cronjobs.batch matter on shared clusters: a misconfigured CronJob spawning jobs every minute can fill a namespace faster than any Deployment.

Apply it, then check accounting immediately:

kubectl apply -f quota.yaml
kubectl describe resourcequota team-payments-quota -n team-payments

1.3 What quotas don’t do

Quota is one control in a stack of controls, and it helps to know where its job ends:

ControlQuestion it answersWhere it acts
ResourceQuotaHow much can this namespace hold?Admission, per namespace
LimitRangeWhat does a pod get/ask for by default?Admission, per container/PVC
Requests/limitsHow is this pod scheduled and throttled?Scheduler + kubelet, runtime
NetworkPolicyWho can talk to whom?CNI dataplane, runtime
RBACWho may create or change objects?API authorization

The distinction that matters most day to day: quota governs capacity, not traffic. It can’t throttle a hot pod, can’t stop a service from being hammered, and can’t prevent a noisy neighbor from hogging a node’s CPU once it’s scheduled. Those are runtime problems handled by requests/limits (throttling and OOM), PriorityClass preemption, and node-level isolation. Quota’s job is narrower and earlier: deciding whether an object gets to exist at all.


2. LimitRange: Default Requests and Limits

A ResourceQuota without a LimitRange is a trap: the first pod that doesn’t declare requests gets rejected, and your on-call learns about quotas from an angry deploy. The LimitRange is what makes the quota livable: it defaults, bounds, and ratios the resources of every container created in the namespace.

2.1 What each field does

  • default: the limit applied to containers that don’t declare one.
  • defaultRequest: the request injected when a container omits it. This is the field that keeps quota-blocked pods out of Forbidden hell, since the injected value is what the quota accounts for.
  • max / min: hard bounds per container. A pod asking for more than max or less than min is rejected at admission.
  • maxLimitRequestRatio: caps how far a limit can outrun its request. A ratio of 4 on CPU stops a container requesting 100m while claiming a 4-core limit, which is how teams game scheduler placement and then wonder why the node is thrashing.

2.2 LimitRange template

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

    # Pod-level limits
    - type: Pod
      max:
        cpu: 4000m
        memory: 8Gi
      min:
        cpu: 100m
        memory: 128Mi

    # Persistent volume claim limits
    - type: PersistentVolumeClaim
      max:
        storage: 50Gi
      min:
        storage: 1Gi

Three details worth noticing:

  • The Pod-level entry bounds the sum of a pod’s containers. Without it, a 20-container pod of default 500m containers asks for 10 cores and eats your entire CPU quota in one object.
  • The PersistentVolumeClaim entry keeps one team from claiming the whole 100 Gi storage quota with a single PVC.
  • Keep defaultRequest comfortably below default. If they’re equal, every pod reserves its limit and you’ll hit quota far earlier than dashboards suggest.

2.3 How the two interact

The mental model: the quota counts effective requests, and the LimitRange fills in whatever a pod didn’t declare. So a container with no resources block lands in the cluster as defaultRequest/default. It’s the LimitRange values, not zero, that consume quota. Tune them together: if defaultRequest is generous, small pods silently burn through requests.cpu and your quota looks broken when it’s actually working as configured.


3. Quota Tiers by Team Size

Picking numbers out of thin air is how quotas end up either useless or hated. The workable method:

  1. Measure first. Let the team run for two to four weeks and record kubectl top and Prometheus usage. A quota is a ceiling on requests, so measure requested resources (kube_pod_container_resource_requests), not just actual usage.
  2. Set the quota near observed requests, not observed usage. If a team requests 8 CPU and burns 3, a 6-CPU quota breaks their next deploy even though the cluster is idle.
  3. Leave rollout headroom. A Deployment’s rolling update runs old and new ReplicaSets at once: for a service with 5 pods, the pod count and request sum briefly double. Quotas sized to exactly current usage turn every rollout into a FailedCreate event. 20–30% headroom is the usual buffer.
  4. Tier it. Most teams fit one of a few standard sizes. Tiers make the quota a product decision instead of a per-namespace negotiation, and they make over-provisioning visible when a “small” team asks for xlarge.

3.1 Worked example

Say the payments team runs three services: an API (4 replicas at 500m CPU / 512Mi requests), a worker (6 replicas at 250m / 256Mi), and a nightly batch job (2 CPU / 4Gi for two hours). Their steady-state request sum is 3.5 CPU and 4.5 Gi; during the batch window it’s 5.5 CPU and 8.5 Gi. A small tier (4 CPU requests) would reject the batch job every night and block rollouts that briefly double a Deployment. standard (10 CPU / 20 Gi) covers the peak plus headroom, which is why it’s the default tier below: it fits the measured need, not the team’s wish list.

3.2 Tier definitions

TierCPU reqMem reqCPU limMem limStoragePods
small48Gi816Gi50Gi20
standard1020Gi2040Gi100Gi50
large2550Gi50100Gi250Gi100
xlarge50100Gi100200Gi500Gi200

These are starting points, not physics. Calibrate against your node sizes; a tier is pointless if one pod’s default limit already exceeds what a node can offer.

3.3 Small team quota

apiVersion: v1
kind: ResourceQuota
metadata:
  name: small-team-quota
  namespace: team-small
  labels:
    quota-tier: small
spec:
  hard:
    requests.cpu: "4"
    requests.memory: 8Gi
    limits.cpu: "8"
    limits.memory: 16Gi
    requests.storage: 50Gi
    persistentvolumeclaims: "5"
    count/pods: "20"
    count/services: "5"
    count/deployments.apps: "5"

3.4 Large team quota

apiVersion: v1
kind: ResourceQuota
metadata:
  name: large-team-quota
  namespace: team-large
  labels:
    quota-tier: large
spec:
  hard:
    requests.cpu: "25"
    requests.memory: 50Gi
    limits.cpu: "50"
    limits.memory: 100Gi
    requests.storage: 250Gi
    persistentvolumeclaims: "20"
    count/pods: "100"
    count/services: "20"
    count/deployments.apps: "20"
    count/statefulsets.apps: "10"

4. Priority Classes and Scoped Quotas

A plain quota treats every pod in the namespace equally: a batch job can soak up quota that a latency-sensitive service needs during its peak. Scoped quotas fix that: a ResourceQuota can select which pods it applies to, so you can carve out a quota slice that only high-priority workloads can consume.

The mechanism is spec.scopeSelector with matchExpressions. For priority classes, the expression is scopeName: PriorityClass with operator: In and the class names in values. Each scoped slice is its own ResourceQuota object — you can’t nest scopes inside hard. (The older spec.scopes field also exists, but it’s the all-or-nothing form: every listed scope must match. scopeSelector supports In, NotIn, Exists and DoesNotExist, which is what you want here.) Other useful scopes are BestEffort (pods with no requests at all), NotBestEffort, Terminating and NotTerminating.

4.1 Priority class definitions

# Critical — system services, never evicted
apiVersion: scheduling.k8s.io/v1
kind: PriorityClass
metadata:
  name: critical
value: 1000000
globalDefault: false
description: "Critical workloads — never preempted"
preemptionPolicy: PreemptLowerPriority

---
# High — production services
apiVersion: scheduling.k8s.io/v1
kind: PriorityClass
metadata:
  name: high-priority
value: 100000
globalDefault: false
description: "Production services"
preemptionPolicy: PreemptLowerPriority

---
# Standard — default for most workloads
apiVersion: scheduling.k8s.io/v1
kind: PriorityClass
metadata:
  name: standard
value: 10000
globalDefault: true
description: "Standard workloads"

---
# Low — batch jobs, can be preempted
apiVersion: scheduling.k8s.io/v1
kind: PriorityClass
metadata:
  name: low-priority
value: 1000
globalDefault: false
description: "Batch jobs — can be preempted"
preemptionPolicy: Never

See Pod Priority and Preemption for how these classes interact with scheduling and eviction. Priority affects which pods the scheduler preempts under pressure, which is a different mechanism from quota but works best when the two line up.

4.2 Quotas scoped by priority class

Scoped quotas are separate objects. The matchExpressions gate which pods count toward that quota’s hard values: a pod only counts if its priorityClassName is in values.

# Slice reserved for high-priority pods
apiVersion: v1
kind: ResourceQuota
metadata:
  name: high-priority-quota
  namespace: team-payments
spec:
  hard:
    requests.cpu: "15"
    requests.memory: 30Gi
    pods: "25"
  scopeSelector:
    matchExpressions:
      - scopeName: PriorityClass
        operator: In
        values: ["high-priority", "critical"]

---
# Slice for low-priority batch work
apiVersion: v1
kind: ResourceQuota
metadata:
  name: low-priority-quota
  namespace: team-payments
spec:
  hard:
    requests.cpu: "5"
    requests.memory: 10Gi
    pods: "15"
  scopeSelector:
    matchExpressions:
      - scopeName: PriorityClass
        operator: In
        values: ["low-priority"]

Two things this buys you:

  • The high-priority-quota slice guarantees 15 cores that batch jobs can’t touch: a low-priority pod never counts toward it and can’t drain it.
  • The low-priority-quota slice caps batch work at 5 cores of requests, so a CI burst can’t consume the whole namespace budget.

Keep a plain unscoped quota alongside these if you want a namespace-wide ceiling; scoped quotas and the unscoped one all apply, and the most restrictive check wins. And remember: a pod only matches a PriorityClass-scoped quota if it actually sets priorityClassName — pods without one fall back to whatever their globalDefault class is, so a standard globalDefault keeps ordinary workloads inside the plain quota.


5. Multi-Tenant Namespace Setup

In practice you never create a quota alone. A team namespace ships as a bundle: the namespace itself, its quota, its LimitRange, a deny-by-default NetworkPolicy, and usually a default ServiceAccount plus RoleBindings. Treating that bundle as one versioned artifact (namespace-as-code) is what makes quota drift reviewable instead of discovered at 3 a.m.

# Namespace
apiVersion: v1
kind: Namespace
metadata:
  name: team-payments
  labels:
    team: payments
    environment: production
    quota-tier: standard

---
# Resource quota
apiVersion: v1
kind: ResourceQuota
metadata:
  name: compute-quota
  namespace: team-payments
spec:
  hard:
    requests.cpu: "10"
    requests.memory: 20Gi
    limits.cpu: "20"
    limits.memory: 40Gi

---
# Limit range
apiVersion: v1
kind: LimitRange
metadata:
  name: default-limits
  namespace: team-payments
spec:
  limits:
    - type: Container
      default:
        cpu: 500m
        memory: 512Mi
      defaultRequest:
        cpu: 100m
        memory: 128Mi
      max:
        cpu: 2000m
        memory: 4Gi

---
# Network policy — deny all ingress by default
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: deny-all-ingress
  namespace: team-payments
spec:
  podSelector: {}
  policyTypes:
    - Ingress
  ingress: []

The GitOps shape for this is a Kustomize overlay per namespace: a base containing the bundle with placeholders, overlays that set the tier label and patch the quota values. Synced through ArgoCD or Flux, a tier change becomes a pull request instead of a kubectl edit. If you template namespaces with Helm, run the result through the Helm Chart Review Checklist — quota and LimitRange defaults are easy to ship twice by accident when both a chart and a cluster policy inject them.


6. Monitoring and Alerting

Quotas fail silently until a deploy is rejected. Monitor used vs hard before that happens: kube-state-metrics exposes both as the kube_resourcequota metric, labeled by resource name and type.

6.1 Quota usage check

# Check quota usage for a namespace
kubectl get resourcequota -n team-payments -o yaml

# Check limit ranges
kubectl get limitrange -n team-payments

# Check pod resource usage (requires metrics-server)
kubectl top pods -n team-payments --sort-by=cpu

# Check namespace resource consumption
kubectl describe resourcequota compute-quota -n team-payments

kubectl top reads live usage from metrics-server, useful for spotting pods whose requests wildly overshoot reality (a sign their requests, and therefore their quota cost, are inflated). kubectl describe on the quota shows used vs hard per tracked resource, which is the number that actually gates admission.

6.2 Prometheus alerts

# Alert: namespace approaching CPU quota limit
- alert: NamespaceCPUQuotaNearLimit
  expr: |
    sum(kube_pod_container_resource_requests{resource="cpu", namespace="team-payments"})
    /
    sum(kube_resourcequota{resource="requests.cpu", namespace="team-payments", type="hard"})
    > 0.85
  for: 10m
  labels:
    severity: warning
    team: payments
  annotations:
    summary: "Namespace {{ $labels.namespace }} CPU quota near limit"
    description: "CPU requests at {{ $value | humanizePercentage }} of quota"

# Alert: namespace exceeding memory limit
- alert: NamespaceMemoryQuotaExceeded
  expr: |
    sum(kube_pod_container_resource_limits{resource="memory", namespace="team-payments"})
    >
    sum(kube_resourcequota{resource="limits.memory", namespace="team-payments", type="hard"})
  for: 5m
  labels:
    severity: critical
    team: payments
  annotations:
    summary: "Namespace {{ $labels.namespace }} memory quota exceeded"

A simpler form of the same alert compares type="used" to type="hard" on kube_resourcequota directly; that tracks what the quota controller counts, which is what admission actually enforces. The requests-based version above is better for spotting inflated requests before they block a rollout.

6.3 Grafana dashboard query

# CPU quota usage by namespace
sum(kube_pod_container_resource_requests{resource="cpu", namespace=~"team-.*"})
by (namespace)
/
sum(kube_resourcequota{resource="requests.cpu", namespace=~"team-.*", type="hard"})
by (namespace)

# Memory quota usage by namespace
sum(kube_pod_container_resource_requests{resource="memory", namespace=~"team-.*"})
by (namespace)
/
sum(kube_resourcequota{resource="requests.memory", namespace=~"team-.*", type="hard"})
by (namespace)

# Pod count vs quota
count(kube_pod_info{namespace=~"team-.*"}) by (namespace)
/
sum(kube_resourcequota{resource="count/pods", namespace=~"team-.*", type="hard"}) by (namespace)

Watch three things in practice: sustained usage above ~80% (grow the tier before the next deploy fails), used pinned at hard on any object-count quota (usually means a controller is retrying creations in a loop), and a growing gap between requests and live usage (requests are padded, so quota is being wasted on paper).


Common Mistakes

Shipping a quota with no LimitRange. The first pod without resources gets Forbidden: exceeded quota (actually failed quota on the request-declaration check) and every Deployment in the namespace stalls. Always deploy the pair together.

Sizing the quota to current usage. Quota is a ceiling on requests, and rollouts temporarily double a workload’s footprint. A quota set to exactly what a team uses today guarantees failed deploys tomorrow; keep 20–30% headroom.

Setting defaultRequest equal to default. Then every container reserves its full limit, quota evaporates, and kubectl describe shows used at ceiling while the cluster idles. Defaults should reflect the small, typical pod; big pods declare their own.

Summing namespace quotas to cluster capacity. Namespaces overcommit; that’s the point. If every quota adds up to 100% of cluster resources, you’ve built a static partition and lost bin-packing. The right sum is above capacity, sized so that realistically concurrent peaks fit.

Forgetting object-count quotas. Compute quotas don’t stop a team from creating five thousand ConfigMaps or a LoadBalancer service per microservice. etcd size and cloud LB spend are quota problems too.

Expecting quotas to protect running pods. Quota is admission control, not QoS. For runtime guarantees you need requests/limits themselves (CPU throttling, OOM behavior), PriorityClass preemption, and Pod Disruption Budgets for voluntary disruptions.


See Also

Frequently Asked Questions

What happens when a namespace hits its resource quota?

The API server starts rejecting new objects. A pod that asks for more CPU or memory than what's left in the quota won't schedule: you'll see FailedCreate on the ReplicaSet and Pending pods with no events of their own. PVCs past the storage cap get refused, and so do ConfigMaps, Secrets or Services once their count quota fills. Nothing already running is touched; quota only gates creation. The way out is either raising the namespace quota or freeing room by scaling down or deleting what's idle.

How do I choose the right quota size for a team?

For most teams the standard tier (10 CPU, 20Gi memory, 50 pods) is the right starting point. Watch actual usage for two to four weeks: kubectl top for a quick read, Prometheus for the trend. If they're running above 80% of quota week over week, bump them up a tier; below 30%, take them down one. Size for peaks, not averages, since batch jobs and rollouts create short spikes on their own. And if the team's roadmap has new services coming, provision for it now. Whatever you pick, keep about 20% headroom for rollouts.

Should I set CPU limits on containers?

They can. The moment a container hits its CPU limit the kernel throttles it — it doesn't die, it just slows down, which shows up as latency spikes and timeouts on latency-sensitive services. That's why a common pattern is requests without limits: the pod gets scheduled sanely but can still burst. The catch is that one unbounded container can eat a whole node's CPU and starve everything else. In practice, set CPU limits on batch jobs and CPU-bound services, and skip them on latency-sensitive work with predictable patterns. Memory is different: always set the limit, because it can't be compressed and going over means OOMKill.

How do LimitRange defaults interact with pod resource requests?

The LimitRange fills in whatever the pod left out. No requests declared means it gets defaultRequest; no limits means it gets default. Declare one but not the other and only the missing side is filled in. The min and max bounds are enforced at admission: ask for more than max or less than min and the pod is rejected on the spot. maxLimitRequestRatio does a related job, stopping a container from claiming a limit wildly out of proportion to its request (say, 4x), which is a common way to game the scheduler.

How do I implement quotas across multiple namespaces efficiently?

GitOps, basically. Keep every namespace's quota as YAML in a Git repo and let ArgoCD or Flux apply it, with Kustomize overlays per namespace carrying the tier. Most teams end up with a namespace template bundling ResourceQuota, LimitRange, a default-deny NetworkPolicy and a ServiceAccount, then wire provisioning into a portal or CLI so creating a namespace brings the bundle with it. Watch usage centrally in Prometheus, alert near limits, and revisit the tiers quarterly against what teams actually consume.