Appearance

CPU throttling, OOM, and eviction

Diagnose three different resource failures using container status, node pressure, and CPU signals.

What you will understand

  • Explain how CPU quota delays runnable work.
  • Recognize a container memory limit violation in termination state.
  • Distinguish an OOM kill from kubelet eviction under node pressure.

Builds on: Topology and resource governance, Informers, caches, and workqueues

Why CPU pressure and memory limits look different

During a traffic spike, some API requests slow down and one worker stops entirely. The resource numbers tell different stories. CPU throttling delays a runnable process after it consumes the CPU time allowed for the current interval. Requests may queue up even while the container keeps running. Compare request latency with CPU usage and throttling counters when available. Check whether the workload could run faster with more CPU or is waiting on something else.

A container can also hit its memory limit. The kernel can reclaim some memory, but if it cannot satisfy demand within the memory boundary it can kill a process. Kubernetes may report OOMKilled when the container terminates. The Pod’s restart policy then controls what happens to that container. Compare the traces in the first scene. A CPU throttle can explain latency without a restart, while a memory kill can explain a termination.

Compare throttling with a memory kill

CPU quota can delay runnable work. A container that exceeds its memory boundary can terminate instead.

  1. Requests guide placement

    • CPU-limited processBurst exceeds available quota
    • CPU quotaExecution delayed
    • Memory-limited processAllocation exceeds enforced limit
    • Kernel OOMMay terminate container
    • Container statusReason + restart evidence

    CPU and memory requests inform scheduling; they are distinct from enforced runtime limits.

  2. CPU quota delays work

    CPU work waits for execution budget, potentially increasing latency without terminating the process.

  3. Memory demand can cause termination

    The enforced memory boundary can trigger a kernel OOM kill recorded in container termination state.

Linux cgroup-style CPU quota and memory behavior is summarized; kernel and runtime accounting affect exact observations.

Inspect CPU and memory limits

Compare two Pods on Linux. A CPU-bound task uses up its quota, while a separate task exceeds its container’s memory limit.

1 / 4

From CPU quotaTo CPU task

Use the allowed CPU time

The CPU task continually asks for CPU. After it uses the runtime available in a scheduling period, the kernel delays it until CPU time is replenished.

CPU task
Before
Runnable and consuming quota
After
Runnable but throttled
Use the allowed CPU time

The CPU task continually asks for CPU. After it uses the runtime available in a scheduling period, the kernel delays it until CPU time is replenished.

The teaching Pods use different limits and deliberately simple workloads. The CPU check reads cgroup v2 counters. The memory Pod uses restartPolicy Never so its termination stays visible.

If a process is still running and nr_throttled rises, which limit explains the observation?
Reveal prediction answer

That counter shows CPU throttling. Inspect the terminated container reason separately when investigating a memory-limit kill.

Compare two reads of cpu.stat and the state of the OOM exercise Pod.

Compare the live CPU and memory evidence
Explore another case

Open Inspect CPU and memory limits to compare a container that stays running while throttled with a separate container killed after hitting its memory limit.

When the kubelet evicts a Pod

Node pressure eviction happens when the kubelet needs to reclaim a scarce resource on the whole node. It may first attempt cleanup such as deleting unused images, then evict Pods if pressure persists. For memory, it ranks candidates using whether usage exceeds requests, priority, and relative usage. The Pod can be marked Failed with reason Evicted even when its containers were below their individual limits. Its controller may create a replacement with a different UID.

Why can the kubelet evict an entire Pod?

Node pressure can force the kubelet to reclaim resources. An evicted workload needs another viable placement to recover.

  1. Observe pressure on the node

    The kubelet detects a configured resource pressure signal and attempts reclaim.

  2. Identify an eviction candidate

    If reclaim is insufficient, the kubelet ranks eligible Pods using relevant usage, requests and priority.

  3. Check recovery capacity

    A controller can create a new Pod, but it still needs a feasible node and does not retain the evicted UID.

Eviction thresholds and ranking depend on the pressured resource and kubelet configuration; QoS is not universal protection.

Explore another case

Inspect a container killed under its memory limit

Start with the CPU comparison in the disposable kind lab. On a cgroup v2 node, read nr_throttled twice. The count can rise while the Pod still reports Running. Then run the existing memory exercise below to compare its termination evidence.

kubectl --context kind-kv-lab get namespace kv-lab >/dev/null 2>&1 || \
  kubectl --context kind-kv-lab create namespace kv-lab
kubectl --context kind-kv-lab -n kv-lab apply -f - <<'YAML'
apiVersion: v1
kind: Pod
metadata:
  name: trace-cpu-limit
spec:
  terminationGracePeriodSeconds: 1
  restartPolicy: Never
  containers:
    - name: busy
      image: busybox:1.37.0
      command: ["sh", "-c", "while true; do :; done"]
      resources:
        limits:
          cpu: 50m
          memory: 16Mi
YAML
kubectl --context kind-kv-lab -n kv-lab wait --for=condition=Ready pod/trace-cpu-limit --timeout=90s
kubectl --context kind-kv-lab -n kv-lab exec trace-cpu-limit -- grep '^nr_throttled ' /sys/fs/cgroup/cpu.stat
sleep 3
kubectl --context kind-kv-lab -n kv-lab exec trace-cpu-limit -- grep '^nr_throttled ' /sys/fs/cgroup/cpu.stat
kubectl --context kind-kv-lab -n kv-lab get pod trace-cpu-limit
kubectl --context kind-kv-lab -n kv-lab delete pod trace-cpu-limit

The teaching example mounts an in-memory emptyDir at /memory. The writer attempts to place 96 MiB in it with a 32 MiB container memory limit. Those file contents count toward memory use, so even a process writing to a filesystem can hit the memory boundary. Treat this as a small disposable experiment. The snippet names the Pod m17-memory. The inspection commands use m17-oom, the separate scenario supplied by the lab. Use the name that matches the exercise you ran.

apiVersion: v1
kind: Pod
metadata:
  name: m17-memory
  namespace: kv-lab
  labels:
    lab: m17
spec:
  restartPolicy: Never
  containers:
    - name: fill
      image: busybox:1.37.0
      command: [dd, if=/dev/zero, of=/memory/blob, bs=1M, count=96]
      resources:
        requests:
          memory: 16Mi
          cpu: 10m
        limits:
          memory: 32Mi
          cpu: 100m
      volumeMounts:
        - name: memory
          mountPath: /memory
  volumes:
    - name: memory
      emptyDir:
        medium: Memory
kubectl --context kind-kv-lab -n kv-lab get pod m17-oom -o yaml
kubectl --context kind-kv-lab -n kv-lab describe pod m17-oom
kubectl --context kind-kv-lab get nodes
kubectl --context kind-kv-lab -n kv-lab get events --sort-by=.metadata.creationTimestamp

In the performance lab, check the actual termination reason, exit code, and node conditions. Compare a container that was killed with the entire Pod being evicted. The exit code alone may be ambiguous.

Check the bottleneck before raising limits

Raising a limit can buy time for a legitimate workload, or move the pressure to the node if the process keeps growing. Observe memory over time, inspect allocations and cache behavior, and read container and node evidence before tuning. Keep runtime limits and placement requests in view together.

Check your understanding

The process is slow but keeps running. Its memory is flat and CPU throttled time rises during peaks. What would you test?

Check whether the process reaches its CPU quota during the slow periods. Compare latency and throughput with a deliberate quota change or less work per replica while keeping other inputs fixed. That can show whether CPU availability explains the delay.

Go to the source

Reviewed 2026-10-27 · Kubernetes 1.37 · Related local exercise

Search the book

Search loads when you open it.

Keyboard shortcuts

Ctrl + K / ⌘ + K
Search the book
?
Open this guide
Tab / Shift + Tab
Move between controls
Enter / Space
Activate a focused button or disclosure
← / →
Focused visual timeline · previous or next step
Home / End
Focused visual timeline · first or last point
Esc
Close the open dialog or menu