Skip to content
Tutorials Center
My learning

Topics

Lesson 32 of 37 ยท Storage and Scaling

Resource Quotas, Limit Ranges and QoS in OpenShift

Share a cluster fairly: requests and limits, QoS classes, ResourceQuota per project, LimitRange defaults, ClusterResourceQuota and what happens when a quota is exceeded.

A cluster is shared by many teams. Without guard rails, one runaway deployment can eat all the CPU or memory and starve everyone else. OpenShift controls this at three levels: each container declares requests and limits, each project can be capped by a ResourceQuota, and a LimitRange sets per-object defaults and bounds.

Commands and YAML are read-only examples; the Python stand-ins let you play with the arithmetic.

Requests and limits

YAML
resources:
  requests:
    cpu: 250m        # what the scheduler reserves
    memory: 256Mi
  limits:
    cpu: "1"         # a ceiling
    memory: 512Mi
  • Request: the amount the scheduler guarantees; a pod is placed only on a node with that much unreserved capacity.
  • Limit: the maximum the container may use. CPU over the limit is throttled (slowed). Memory over the limit makes the container OOMKilled.
  • CPU units: 1 is one core, 250m is a quarter of a core. Memory uses Mi, Gi (binary) or M, G (decimal).

QoS classes

Kubernetes labels each pod with a Quality of Service class that decides who is evicted first when a node runs out of memory:

Class Condition Eviction order
Guaranteed Every container has requests equal to limits for CPU and memory Last
Burstable At least one request or limit set, but not Guaranteed Middle
BestEffort No requests or limits at all First
Python Stand-in: classify a pod's QoS

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.

Check a pod's class with oc get pod NAME -o jsonpath='{.status.qosClass}'.

ResourceQuota

A quota caps the total a project may consume or the number of objects it may create:

YAML
apiVersion: v1
kind: ResourceQuota
metadata:
  name: compute-and-objects
  namespace: shop
spec:
  hard:
    requests.cpu: "4"
    requests.memory: 8Gi
    limits.cpu: "8"
    limits.memory: 16Gi
    pods: "20"
    persistentvolumeclaims: "5"
    requests.storage: 100Gi
    services.loadbalancers: "0"
Terminal
oc create quota compute --hard=requests.cpu=4,requests.memory=8Gi,pods=20 -n shop
oc get quota -n shop
oc describe quota compute -n shop       # Used vs Hard

When a request would push usage over a hard limit, the API rejects it:

TEXT
Error from server (Forbidden): pods "shop-api-3" is forbidden: exceeded quota: compute,
requested: requests.cpu=500m, used: requests.cpu=3800m, limited: requests.cpu=4

When a quota covers requests.cpu or limits.memory, every pod must declare them, otherwise creation fails. That is where LimitRange helps.

Python Stand-in: 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.

LimitRange

A LimitRange sets defaults and sanity bounds for individual containers and pods in one project:

YAML
apiVersion: v1
kind: LimitRange
metadata:
  name: container-defaults
  namespace: shop
spec:
  limits:
    - type: Container
      default:            # applied as limit when missing
        cpu: 500m
        memory: 512Mi
      defaultRequest:     # applied as request when missing
        cpu: 100m
        memory: 128Mi
      max:
        cpu: "2"
        memory: 2Gi
      min:
        cpu: 50m
        memory: 64Mi
    - type: PersistentVolumeClaim
      max:
        storage: 50Gi

Containers created without resources receive the defaults, so quotas keep working and BestEffort pods disappear. A container that asks for more than max is rejected.

Python Stand-in: apply LimitRange defaults

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.

Cluster-wide: ClusterResourceQuota

OpenShift adds ClusterResourceQuota, which applies one budget across many projects selected by label or annotation, for example every project owned by a team:

Terminal
oc create clusterquota team-a \
  --project-label-selector=team=a \
  --hard=requests.cpu=20,requests.memory=64Gi,pods=100
oc describe clusterquota team-a

Admins can also set a default quota and limit range in the project request template so new projects are never unlimited.

Practical advice

  • Start from measured usage (oc adm top pods, monitoring graphs), then set requests near typical use and limits near the peak.
  • Do not set CPU limits too low: throttling can cause latency even when the node is idle.
  • Set memory request equal to limit for critical services (Guaranteed class).
  • Leave headroom in quotas for rolling updates, which temporarily run extra pods.

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 container; CPU over the limit is throttled.
  2. 2. Which pod gets the Guaranteed QoS class?

    Guaranteed needs requests equal to limits for CPU and memory in every container.
  3. 3. A project quota covers requests.cpu and a pod without CPU requests is created. What happens?

    Quotas require explicit values; LimitRange defaults fill them in.
  4. 4. What is a ClusterResourceQuota used for?

    It aggregates usage over all projects matching a selector.

Summary

  • Requests reserve capacity; limits cap use (CPU throttled, memory OOMKilled).
  • QoS classes decide eviction order: Guaranteed, Burstable, BestEffort.
  • ResourceQuota caps a project's totals and object counts.
  • LimitRange sets defaults and per-container min/max.
  • ClusterResourceQuota shares one budget across projects.

Next: Cluster monitoring and alerts