CKAD — Requests & Limits

less than 1 minute read

Requests and Limits

Requests

  • The minimum resources guaranteed to the container
  • Used by the scheduler to decide which node to place the Pod on
  • The container is guaranteed to have this much CPU and memory

Limits

  • The maximum resources the container can use
  • If the container exceeds the memory limit, it is OOMKilled (Out of Memory killed)
  • If the container exceeds the CPU limit, it is throttled (slowed down, not killed)

Setting Requests and Limits

apiVersion: v1
kind: Pod
metadata:
  name: app
spec:
  containers:
  - name: app
    image: nginx:1.27
    resources:
      requests:
        cpu: 250m
        memory: 128Mi
      limits:
        cpu: 500m
        memory: 256Mi
# Imperative way (on a Deployment)
kubectl set resources deployment/web -c nginx \
  --requests=cpu=250m,memory=128Mi \
  --limits=cpu=500m,memory=256Mi

What Happens Without Requests/Limits

Scenario CPU Behavior Memory Behavior
No requests, no limits Can use all available CPU Can use all available memory
Requests only Guaranteed minimum, can burst above Guaranteed minimum, can use more
Limits only Requests = Limits (capped) Requests = Limits (capped)
Both Guaranteed minimum, capped at limit Guaranteed minimum, killed if exceeds limit

Next: QoS Classes →

Updated: