Kubernetes Requests and Limits

Set CPU and memory requests and limits, understand throttling and OOM kills, and learn how QoS classes affect pod behavior.

Requests vs Limits

resources.requests tell Kubernetes how much resource a container is expected to need. resources.limits tell Kubernetes the maximum it can consume.

Full YAML Example

apiVersion: v1
kind: Pod
metadata:
  name: resources-demo
spec:
  containers:
    - name: app
      image: nginx:1.27
      resources:
        requests:
          cpu: "250m"
          memory: "256Mi"
        limits:
          cpu: "500m"
          memory: "512Mi"

Enforcement Differences

ResourceWhat happens at limit
CPUThe container may be throttled
MemoryThe container may be killed with OOMKill

QoS Classes

QoS classGeneral meaning
GuaranteedRequests and limits set equally for all containers
BurstableSome requests or limits set, but not fully guaranteed
BestEffortNo requests or limits set

LimitRange for Namespace Defaults

A LimitRange can set default requests and limits so teams do not forget them.

Observe Resource Usage

kubectl top pods
kubectl top nodes

These commands rely on metrics-server being installed.

Why This Matters in Practice

If requests are too high, the scheduler may waste cluster capacity. If limits are too low, the app may be throttled or killed. Good tuning balances reliability and efficiency.

Think of requests as reserving seats on a train and limits as the maximum luggage weight allowed.

Exercise

CPU Limit Effect

What usually happens when a container tries to use more CPU than its limit?

Exercise

Memory Limit Effect

What usually happens when a container exceeds its memory limit?

Continue Learning

Explore Related Topics

Try the Tool

Related Resources