Skip to content
Tutorials Center
My learning

Topics

Lesson 13 of 37 ยท Projects and Workloads

Resource Requests, Limits and Quotas

Set CPU and memory requests and limits, understand QoS classes and OOMKilled, and see how LimitRange and ResourceQuota keep a shared OpenShift cluster fair.

A cluster has finite CPU and memory. If every app could take as much as it wanted, one runaway process could starve its neighbors. OpenShift uses three layers of control: requests and limits on containers, LimitRange defaults per project, and ResourceQuota totals per project.

Requests and limits

YAML
containers:
  - name: web
    image: quay.io/example/web:1.0
    resources:
      requests:
        cpu: 250m
        memory: 256Mi
      limits:
        cpu: "1"
        memory: 512Mi
  • A request is what the scheduler reserves for the container. A Pod is placed only on a node with enough unreserved capacity.
  • A limit is the ceiling at runtime.

Units: CPU is measured in cores; 250m means 250 millicores (a quarter of a core). Memory uses Mi and Gi (powers of 1024); 256Mi is 256 mebibytes.

What happens at the limit differs:

  • CPU over the limit is throttled. The container slows down but keeps running.
  • Memory over the limit cannot be throttled. The kernel kills the process, and the container shows OOMKilled (exit code 137) and restarts.
Terminal
oc set resources deployment/web --requests=cpu=250m,memory=256Mi --limits=cpu=1,memory=512Mi
oc describe pod <name> | grep -A4 -i "last state"
oc adm top pods
oc adm top nodes

oc adm top needs the cluster metrics, which OpenShift provides through its monitoring stack.

Quality of Service classes

From requests and limits, each Pod receives a QoS class that decides who is evicted first when a node runs low:

Class Rule Eviction order
Guaranteed Every container has requests equal to limits for CPU and memory Last
Burstable At least one request or limit set, not Guaranteed Middle
BestEffort No requests or limits First

Production services normally set requests, and for critical ones, requests equal to limits. Setting no requests is a risk: the scheduler assumes your Pod needs nothing and may overpack nodes.

Choosing numbers

  1. Run the app under realistic load and observe usage (oc adm top pods, or the Observe section in the console).
  2. Set the request near typical usage (often a high percentile).
  3. Set the memory limit with headroom above the observed peak. For the JVM and other runtimes with their own heap settings, make sure the heap fits inside the container limit.
  4. Be careful with low CPU limits on latency-sensitive services; throttling shows up as slow responses. Some teams set CPU requests but no CPU limit.

LimitRange

A LimitRange sets defaults and minimum or maximum values for individual containers in a project. If a Pod omits resources, the defaults fill them in.

YAML
apiVersion: v1
kind: LimitRange
metadata:
  name: container-limits
spec:
  limits:
    - type: Container
      default:
        cpu: 500m
        memory: 512Mi
      defaultRequest:
        cpu: 100m
        memory: 128Mi
      max:
        cpu: "2"
        memory: 2Gi

A request above max is rejected at admission time with a clear error.

ResourceQuota

A ResourceQuota limits the totals a whole project can use, and can also cap object counts.

YAML
apiVersion: v1
kind: ResourceQuota
metadata:
  name: compute-quota
spec:
  hard:
    requests.cpu: "4"
    requests.memory: 8Gi
    limits.cpu: "8"
    limits.memory: 16Gi
    pods: "20"
    persistentvolumeclaims: "5"
    requests.storage: 50Gi
Terminal
oc describe quota compute-quota
oc get resourcequota -o yaml

When a quota covers CPU or memory, every new Pod must state those values (or get them from a LimitRange); otherwise it is rejected. When the quota is exhausted, new Pods fail with exceeded quota, and ReplicaSets show the error in their events, not in Pod events. When a Deployment will not scale, run oc describe replicaset or oc get events.

Administrators can also define a ClusterResourceQuota, which spans several projects selected by label or owner, useful for team-level budgets.

Stand-in: will the Pod fit the node?

This stand-in models the scheduler's resource check with requests only.

Python Stand-in: node fit by requests

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Stand-in: QoS classifier and quota check

Python Stand-in: QoS class and quota admission

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Common mistakes

  • No requests at all: BestEffort Pods are evicted first and distort scheduling.
  • Memory limit below real peak: endless OOMKilled restarts.
  • Limit much larger than request on every Pod: nodes get overcommitted and run out of memory under load.
  • Forgetting ReplicaSet events when a quota blocks scaling.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What happens when a container exceeds its memory limit?

    Memory cannot be throttled, so the kernel kills the process and the container restarts.
  2. 2. Which QoS class has requests equal to limits for all containers?

    Guaranteed Pods are evicted last under node pressure.
  3. 3. What does a ResourceQuota limit?

    A ResourceQuota caps aggregate resources and object counts in one project; LimitRange governs single containers.
  4. 4. The scheduler places Pods based on which numbers?

    Scheduling reserves capacity by requests.

Summary

  • Requests reserve capacity; limits cap runtime use. CPU is throttled, memory overuse means OOMKilled.
  • QoS classes (Guaranteed, Burstable, BestEffort) decide eviction order.
  • LimitRange sets per-container defaults and maxima; ResourceQuota caps project totals.
  • Size from measurements, and check ReplicaSet events when a quota blocks a rollout.

Next: YAML Manifests and oc apply