Repaso
Español
Cloud & DevOpsIntermediateOPS-49

What is the difference between Kubernetes resource requests and limits?

Options

  1. Requests are reserved for scheduling; limits are the maximum allowed (Correct option)
  2. They are the same value, just written in two different places
  3. Limits are the minimum amounts and requests are the maximums
  4. Requests are only used for storage and never for CPU or memory

Answer

Requests: the amount reserved for scheduling (guaranteed); limits: the maximum a container may use (exceeding memory kills it, exceeding CPU throttles it)

Why

For each container you can set CPU and memory.

  • requests: what the scheduler reserves; Kubernetes places the Pod on a node that has this much free.
  • limits: the ceiling. If a container exceeds its memory limit it is killed (OOMKilled, exit code 137). If it exceeds its CPU limit it is slowed down (throttled).

Without requests the scheduler cannot plan well; the HPA also uses requests to calculate CPU percentage.

For the JVM, make sure the heap fits inside the memory limit.

resources:
  requests: { cpu: "250m", memory: "512Mi" }
  limits:   { cpu: "1",    memory: "1Gi" }

Remember

Request = guaranteed for scheduling. Limit = hard ceiling.

Key terms

Practice this question in Repaso