Skip to main content

How to Set Kubernetes Resource Quotas Without Killing Developer Velocity

· 11 min read

Resource quotas are the most effective tool for preventing Kubernetes cost surprises. They're also the fastest way to make your development teams hate the platform team. The difference between the two outcomes is entirely in how you set them up.

Why Quotas Go Wrong​

The typical quota rollout looks like this:

  1. Finance complains about cloud costs.
  2. Platform team sets quotas on every namespace.
  3. Developers hit quota limits during normal work.
  4. Developers file tickets asking for quota increases.
  5. Platform team becomes a bottleneck for every deployment.
  6. Someone with admin access removes the quotas "temporarily."
  7. Cloud costs go back up.

The problem isn't quotas — it's that most teams set them based on what they think namespaces should use instead of what they actually use. And they set them once, at a single level, with no visibility for the developers who have to live within them.

The Right Mental Model​

Think of quotas as three separate controls, each serving a different purpose:

ControlWhat it limitsWho it protectsExample
ResourceQuotaTotal CPU/memory a namespace can requestFinance — prevents runaway costs"This namespace can request up to 16 cores total"
LimitRangePer-pod/container min/max and defaultsInfrastructure — prevents single pods from starving others"No single container can request more than 4 cores"
PriorityClassWhich pods survive when resources are scarceReliability — production workloads survive eviction"Production pods preempt staging pods"

Most teams only use ResourceQuota. Using all three together is what makes quotas livable.

Step 1: Measure Before You Set​

Never set quotas from gut feeling. Start by measuring what each namespace actually uses:

# Current resource requests by namespace
kubectl get pods -A -o json | jq -r '
.items[] |
select(.status.phase == "Running") |
{
namespace: .metadata.namespace,
cpu_request: ([.spec.containers[].resources.requests.cpu // "0"] |
map(if endswith("m") then (rtrimstr("m") | tonumber / 1000) else tonumber end) | add),
memory_request_gi: ([.spec.containers[].resources.requests.memory // "0"] |
map(if endswith("Gi") then rtrimstr("Gi") | tonumber
elif endswith("Mi") then rtrimstr("Mi") | tonumber / 1024
elif endswith("Ki") then rtrimstr("Ki") | tonumber / 1048576
else tonumber / 1073741824 end) | add)
}' | jq -s 'group_by(.namespace) | map({
namespace: .[0].namespace,
total_cpu: (map(.cpu_request) | add | . * 100 | round / 100),
total_memory_gi: (map(.memory_request_gi) | add | . * 100 | round / 100),
pod_count: length
}) | sort_by(-.total_cpu)' | jq -r '
.[] | "\(.namespace)\t\(.total_cpu) cores\t\(.total_memory_gi) GiB\t\(.pod_count) pods"'

With Prometheus (more accurate — covers time-based peaks):

# Peak CPU requests per namespace over 30 days
max_over_time(
sum by (namespace) (
kube_pod_container_resource_requests{resource="cpu"}
)[30d:]
)

The output tells you what your quotas should be relative to. If payments peaks at 8 cores over 30 days, setting its quota at 8 cores will break it the moment someone scales up by one pod. Setting it at 32 cores is free money left on the table. Set the quota at 1.5-2x the 30-day peak.

Step 2: Set ResourceQuota With Headroom​

The golden rule: quota = peak usage * headroom multiplier.

Namespace typeHeadroom multiplierWhy
Production1.5xNeeds room for rollout (2x replicas briefly) and incident response
Staging1.25xLess critical, tighter is OK
Development1.5xDevelopers experiment and deploy often
CI/CD2.0xBurst workloads, highly variable
Shared/platform1.25xStable, predictable workloads
apiVersion: v1
kind: ResourceQuota
metadata:
name: compute-quota
namespace: payments-prod
spec:
hard:
requests.cpu: "12" # Peak was 8, * 1.5 = 12
requests.memory: "48Gi" # Peak was 32Gi, * 1.5 = 48
limits.cpu: "24" # 2x requests (allow burst)
limits.memory: "48Gi" # Memory limits should equal requests (no overcommit)
pods: "50" # Sanity check on pod count
persistentvolumeclaims: "20"

Critical: set both requests and limits quotas. If you only set requests.cpu, developers can set limits to 100 cores per pod. If you only set limits.cpu, developers can set requests to zero and overcommit your nodes.

Memory: No Overcommit​

Notice that limits.memory equals requests.memory. This is intentional. Memory overcommit is dangerous:

  • A pod that exceeds its memory limit gets OOM-killed immediately
  • A node with overcommitted memory leads to cascading OOM kills
  • There's no "throttle memory" like there is for CPU

CPU overcommit is fine (pod gets throttled). Memory overcommit is a ticking time bomb. Set memory limits equal to requests in your quota.

Step 3: Set LimitRange Defaults​

Here's where most teams stop — and where most developer frustration starts. Without LimitRange, developers must specify resources on every container. Miss one, and the deployment is rejected by the quota (because the admission controller can't verify compliance without a request value).

Fix this with defaults:

apiVersion: v1
kind: LimitRange
metadata:
name: resource-defaults
namespace: payments-prod
spec:
limits:
- type: Container
default: # Default limits (if not specified)
cpu: "500m"
memory: "512Mi"
defaultRequest: # Default requests (if not specified)
cpu: "100m"
memory: "128Mi"
max: # Hard ceiling per container
cpu: "4"
memory: "8Gi"
min: # Floor per container
cpu: "10m"
memory: "16Mi"
- type: Pod
max:
cpu: "8" # No single pod can request > 8 cores
memory: "16Gi"

This does three things:

  1. Developers who forget resource specs get sensible defaults instead of rejected deployments.
  2. No single container can starve the namespace — the max prevents one pod from claiming all 12 cores.
  3. Tiny requests are blocked — the min prevents pods that request 1m CPU and then burst to 4 cores, destabilizing the node.

Choosing Good Defaults​

Bad defaults are worse than no defaults. If your default request is too high, every pod reserves more than it needs and teams hit quotas faster. If it's too low, pods get throttled.

Set the default request to the median resource usage of pods in the namespace. Not the mean (which is skewed by outliers), not the max (which is wasteful) — the median.

# Median CPU usage per container in a namespace (for setting default request)
quantile(0.5,
rate(container_cpu_usage_seconds_total{
namespace="payments-prod",
container!="POD",
container!=""
}[7d])
)

Step 4: Set Up Priority Classes​

When your cluster runs low on resources, Kubernetes needs to decide which pods to evict. Without priority classes, this decision is essentially random.

# System-critical (never evict)
apiVersion: scheduling.k8s.io/v1
kind: PriorityClass
metadata:
name: system-critical
value: 1000000
globalDefault: false
description: "System services: monitoring, ingress, cert-manager"
---
# Production workloads
apiVersion: scheduling.k8s.io/v1
kind: PriorityClass
metadata:
name: production
value: 100000
globalDefault: false
description: "Production application workloads"
---
# Default for everything else
apiVersion: scheduling.k8s.io/v1
kind: PriorityClass
metadata:
name: default
value: 1000
globalDefault: true
description: "Development, staging, preview environments"

With this setup:

  • If the cluster is full and a production pod needs to schedule, Kubernetes evicts a default-priority pod (staging/dev) to make room.
  • System-critical pods are never evicted for application workloads.
  • Developers can deploy freely in dev/staging knowing their pods might be preempted — but production is safe.

This is what makes tight quotas on non-production namespaces tolerable. Developers know that even if their staging pods get preempted, production stays up.

Step 5: Make Quotas Visible​

The number one developer complaint about quotas isn't that they exist — it's that they're invisible until you hit them. A deployment fails with a cryptic forbidden: exceeded quota error, and the developer has to kubectl describe quota to figure out what's full.

Give developers a dashboard showing their quota usage before they deploy:

# Quick quota check (for developers to run before deploying)
kubectl get resourcequota -n payments-prod -o custom-columns=\
NAME:.metadata.name,\
CPU_USED:.status.used.requests\\.cpu,\
CPU_HARD:.status.hard.requests\\.cpu,\
MEM_USED:.status.used.requests\\.memory,\
MEM_HARD:.status.hard.requests\\.memory,\
PODS_USED:.status.used.pods,\
PODS_HARD:.status.hard.pods

Better yet, build quota visibility into your CI/CD pipeline. Before a deployment starts, check whether the new pod will fit within the quota:

#!/bin/bash
# Pre-deploy quota check
NAMESPACE="$1"
ADDITIONAL_CPU="$2" # e.g., "500m" for the new pod
ADDITIONAL_MEM="$3" # e.g., "512Mi"

QUOTA=$(kubectl get resourcequota -n "$NAMESPACE" -o json)
USED_CPU=$(echo "$QUOTA" | jq -r '.items[0].status.used["requests.cpu"]')
HARD_CPU=$(echo "$QUOTA" | jq -r '.items[0].status.hard["requests.cpu"]')

# Convert to millicores for comparison
# ... (conversion logic)

if [ "$NEW_TOTAL" -gt "$HARD_MILLI" ]; then
echo "WARNING: Deployment will exceed CPU quota ($NEW_TOTAL > $HARD_MILLI millicores)"
echo "Request a quota increase before deploying."
exit 1
fi

Tools like K8Cost provide this visibility automatically, showing per-namespace quota utilization alongside cost data so teams see both capacity and cost impact in a single view.

Step 6: Automate Quota Adjustments​

Static quotas break eventually. Teams grow. Traffic patterns change. A team that needed 8 cores six months ago might need 16 today. If every quota change requires a platform team ticket, you're back to the bottleneck problem.

Option 1: Self-service within guardrails

Let teams adjust their own quotas up to a namespace-level budget ceiling:

# Namespace annotation defining the budget ceiling
metadata:
annotations:
quota-ceiling/requests.cpu: "32" # Team can self-adjust up to 32 cores
quota-ceiling/requests.memory: "128Gi"

A simple operator watches for quota change requests (via a CRD or annotation) and approves them as long as they're below the ceiling. Exceeding the ceiling requires platform team approval.

Option 2: Auto-scaling quotas based on usage

If you have Prometheus, a CronJob can adjust quotas automatically:

apiVersion: batch/v1
kind: CronJob
metadata:
name: quota-adjuster
namespace: kube-system
spec:
schedule: "0 * * * *" # Hourly
jobTemplate:
spec:
template:
spec:
serviceAccountName: quota-adjuster
containers:
- name: adjuster
image: bitnami/kubectl:latest
command:
- /bin/sh
- -c
- |
for ns in $(kubectl get ns -l auto-quota=true -o name); do
ns_name=$(echo "$ns" | cut -d/ -f2)
# Get current usage
used=$(kubectl get resourcequota -n "$ns_name" -o jsonpath='{.items[0].status.used.requests\.cpu}')
hard=$(kubectl get resourcequota -n "$ns_name" -o jsonpath='{.items[0].status.hard.requests\.cpu}')
# If usage > 80% of quota, bump by 25%
# If usage < 40% of quota, shrink by 25%
# ... (arithmetic and kubectl patch)
done
restartPolicy: OnFailure

Option 3: Just alert on approaching limits

If auto-adjustment feels risky, start with alerts:

# Alert when namespace is at 80% of CPU quota
(
kube_resourcequota{type="used", resource="requests.cpu"}
/
kube_resourcequota{type="hard", resource="requests.cpu"}
) > 0.80

An alert at 80% gives teams time to right-size or request an increase before they hit the wall.

Common Mistakes​

1. Same Quotas Everywhere​

Production and staging have fundamentally different needs. Production needs headroom for rollouts and incidents. Staging can be much tighter because downtime there is a minor inconvenience.

# Production: generous
requests.cpu: "16"
requests.memory: "64Gi"

# Staging: tight
requests.cpu: "4"
requests.memory: "16Gi"

# Dev: tighter, but with burst allowed
requests.cpu: "2"
requests.memory: "8Gi"

2. Quotas Without LimitRange Defaults​

Without defaults, every container that doesn't specify resources causes a deployment failure. This is the single most common source of developer frustration with quotas. Always deploy LimitRange alongside ResourceQuota.

3. Quotas on kube-system​

Don't quota system namespaces unless you know exactly what's in them and how they scale. A ResourceQuota on kube-system that blocks coredns from scaling up during a DNS storm will cause a cluster-wide outage.

4. Hard Pod Limits Too Low​

A pods: "10" limit sounds reasonable until you realize that a deployment rollout temporarily doubles the pod count (old pods + new pods). Set pod limits to at least 2x the steady-state count.

5. No GPU/Storage Quotas​

If you have GPU nodes or expensive storage classes, quota them separately:

requests.nvidia.com/gpu: "2"
gold-storage.storageclass.storage.k8s.io/requests.storage: "100Gi"

Without this, a single team can consume all your GPUs or provision 10TB of premium SSD storage.

Key Takeaways​

  • Measure before you set. Quotas based on gut feeling always break.
  • Set quotas at 1.5-2x peak usage, not at current usage.
  • Always deploy LimitRange alongside ResourceQuota — defaults prevent deployment failures.
  • Use PriorityClass to make tight non-production quotas tolerable.
  • Make quota usage visible to developers before they deploy, not after they fail.
  • Automate quota adjustments or at least alert at 80% utilization.
  • Memory limits should equal memory requests. CPU can overcommit safely; memory cannot.

Quotas don't have to be a tax on developer velocity. Done right, they're invisible guardrails that keep costs predictable while giving teams room to move fast. The platform team's goal isn't to restrict resources — it's to make cost-aware deployment the path of least resistance.