How do I set Kubernetes requests and limits correctly?

What Kubernetes requests and limits do, how to pick values from real usage, when to skip CPU limits and how VPA and HPA fit in. With the commands to check each step.

How do I set Kubernetes requests and limits correctly?

Set requests to what the container really uses under normal load, so the scheduler places it on a node with room for it. Set a memory limit close to the request, because a container that goes over its memory limit can be OOMKilled. Be careful with CPU limits, since a container that hits one is throttled and gets slower.

Wrong requests and limits cause two kinds of pain. If they are too low, pods get OOMKilled, throttled or evicted. If they are too high, you pay for nodes that sit mostly idle. This guide shows how to pick values from data rather than guesswork.

What requests and limits do

  • A request is what the scheduler uses to pick a node. The kubelet reserves at least that amount for the container. A container can use more than its request when the node has spare capacity.
  • A memory limit is enforced by the kernel. A container that goes over it may be OOMKilled when the node is under memory pressure. See OOMKilled.
  • A CPU limit is enforced by throttling. The container is never killed for CPU, it just gets slower. See CPU throttling.
  • CPU is measured in cores. One CPU is one physical core or one virtual core. 500m is half a core. Memory uses bytes, so write Mi and Gi rather than M and G.

A typical container spec looks like this. It asks for a quarter of a core and 256 MiB, caps memory at the same value and sets no CPU limit.

resources:
  requests:
    cpu: 250m
    memory: 256Mi
  limits:
    memory: 256Mi

The QoS class follows from your choices

Kubernetes gives each pod a QoS class from its requests and limits. The class decides which pods go first when a node runs short of memory.

  • Guaranteed. Every container sets CPU and memory requests equal to its limits. These pods are the last to be evicted.
  • Burstable. At least one container sets a request or limit, but the pod does not meet the Guaranteed rule. The example above is Burstable.
  • BestEffort. No container sets any request or limit. These pods are evicted first.
kubectl get pod <pod-name> -n <namespace> -o jsonpath='{.status.qosClass}'

Step 1: measure what the container really uses

Start with the current numbers. kubectl top needs metrics-server in the cluster.

# Current usage per container
kubectl top pod <pod-name> -n <namespace> --containers

# What the pod asks for today
kubectl get pod <pod-name> -n <namespace> -o jsonpath='{.spec.containers[*].resources}'

# How full the node is, by requests
kubectl describe node <node-name>

A single reading is not enough. Look at a normal week in Prometheus or your metrics tool, with the daily peak and any batch jobs in it. Set the memory request near the peak you see in normal running. Set the CPU request near typical busy usage, not the rare spike.

Step 2: check for OOMKilled restarts

If a container was killed for memory, the pod's last state says so.

kubectl describe pod <pod-name> -n <namespace>
# Look under Last State for: Reason: OOMKilled

kubectl get pod <pod-name> -n <namespace> -o jsonpath='{.status.containerStatuses[*].lastState.terminated.reason}'

A one-off OOMKill after a traffic spike usually means the limit is too tight. A container whose memory climbs until it is killed again and again is more often a leak. Raising the limit only delays the next kill.

Step 3: check for CPU throttling

Throttling does not show up in kubectl. The cAdvisor metrics in Prometheus show it. This query gives the share of CPU periods in which the container was throttled.

sum by (container) (rate(container_cpu_cfs_throttled_periods_total{namespace="<namespace>", pod="<pod-name>"}[5m]))
/
sum by (container) (rate(container_cpu_cfs_periods_total{namespace="<namespace>", pod="<pod-name>"}[5m]))

Steady throttling on a latency-sensitive service is a sign the CPU limit is too low or not needed. Raise it or remove it, then watch latency.

Should you set CPU limits at all?

There is no single right answer. A CPU limit protects the node from one runaway container. It also slows the container down at the moment it is busiest. A common pattern is a CPU request on every container, a memory limit on every container and a CPU limit only where you need a hard cap, such as in a shared cluster with noisy tenants.

Whatever you choose, always set requests. Pods without them can be scheduled onto nodes that are already full. That is how a quiet node turns into a Pending pod problem or an eviction storm later.

Rightsizing pods with VPA

The Vertical Pod Autoscaler watches usage and recommends requests. It is a separate add-on, not part of core Kubernetes. Start it in Off mode so it only writes recommendations and never restarts anything.

apiVersion: autoscaling.k8s.io/v1
kind: VerticalPodAutoscaler
metadata:
  name: <app-name>-vpa
  namespace: <namespace>
spec:
  targetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: <app-name>
  updatePolicy:
    updateMode: "Off"
kubectl describe vpa <app-name>-vpa -n <namespace>

The update modes are Off, Initial, Recreate, InPlaceOrRecreate and InPlace. Auto still works but is deprecated and behaves like Recreate. Review the recommendations by hand before you let VPA apply them in production.

VPA vs HPA

  • HPA (Horizontal Pod Autoscaler) changes the number of replicas. It is built into Kubernetes.
  • VPA changes the requests of each replica. It is an add-on.
  • Do not let both act on CPU for the same workload unless your platform supports it. On GKE, for example, the docs point to a combined mode for that case.
  • A pairing that works: HPA on a custom or external metric such as queue depth, with VPA setting requests.

Resizing without a restart

In-place resize of container resources is stable since Kubernetes v1.35. You patch the pod's resize subresource and the kubelet applies the new values. You need kubectl v1.32 or later for the flag.

kubectl patch pod <pod-name> -n <namespace> --subresource resize --patch '{"spec":{"containers":[{"name":"<container-name>","resources":{"requests":{"cpu":"<new-cpu>"},"limits":{"cpu":"<new-cpu-limit>"}}}]}}'

This changes the running pod only. Update the Deployment too, or the next rollout puts the old values back.

Where KubeGraf fits

KubeGraf watches your clusters for failures such as CrashLoopBackOff, OOMKilled pods and stuck rollouts. When a pod is OOMKilled, specialist agents pull the logs, events, metrics, workloads and recent deploys for it into one view. The FinOps agent finds unused spend, such as requests far above real usage. SafeFix prepares the change. A person, or a policy you set, approves it. See the AI engine.

For the cost side on AWS, read How do I cut EKS costs?. For the wider picture, see Kubernetes cost optimization.

Sources

Read on 23 November 2026. Cloud products change often, so check the source before you rely on a detail.

Frequently asked questions

What is the difference between requests and limits in Kubernetes?

A request is what the scheduler reserves for a container on a node. A limit is the most the container may use. Going over a memory limit can get the container killed, while a CPU limit slows it down by throttling.

Should I set CPU limits?

It depends on the workload. A CPU limit stops one container from taking a whole node, but a container that hits it is throttled. A common approach is a CPU request on every container and a CPU limit only where you need a hard cap.

How do I rightsize pods?

Compare real usage over a normal week, peaks included, with the requests you set. Lower requests that sit far above usage and raise the ones close to their limit. Change one workload at a time and watch for OOMKilled restarts and throttling.

VPA vs HPA: which one should I use?

HPA changes how many replicas run. VPA changes the requests of each pod and is an add-on you install separately. Do not let both act on CPU for the same workload unless your platform supports it, but HPA on a custom metric with VPA on requests works.

What happens when a pod has no requests?

If no container in the pod sets requests or limits, the pod gets the BestEffort QoS class. The scheduler treats it as needing nothing, so it can land on a node that is already full. It is also among the first pods evicted when the node runs short of memory.

Want to see it on one of your own clusters? Apply for KubeGraf Freemium. It runs for three calendar months by approval, with no card and no automatic paid conversion.

Last updated . Try KubeGraf Freemium.