Cloud Computing

Kubernetes pods OOM-killed despite plentiful node memory due to cgroup v2 memory.high vs kubelet eviction mismatch

Environment

Environment

On-prem K8s 1.24 cluster running kubelet with cgroup v2 enabled on Ubuntu 22.04 nodes. Pods scheduled with resource requests/limits (memory limits present). Node has 128 GB RAM; during batch jobs pods are OOM-killed even though node allocatable memory shows plenty free. Kubelet version 1.24.3, container runtime containerd 1.6.

Symptoms

Symptoms

Multiple pods receive SIGKILL and kubectl describe pod shows 'OOMKilled'. Node-level free memory high (top, free -h), but dmesg shows kernel memory cgroup pressure and OOM events tied to the pod's cgroup. kubelet logs show eviction decisions triggered despite no global node eviction threshold reached.

Observations

Observations

cgroup v2 is active (mountpoint /sys/fs/cgroup). cat /sys/fs/cgroup/memory.current shows pods' cgroup usage exceeds memory.high. kubelet is configured with eviction thresholds based on nodefs and memory.available. The per-cgroup memory.high enforcement is causing kernel to throttle/kill processes before kubelet evictions. Pod memory limits close to real usage; some pods spawn many worker threads increasing RSS beyond expected peak.

Already attempted

Already attempted

Increased pod memory limits, restarted kubelet (no immediate effect), disabled memory swap with swapoff (system already had swap disabled). Tried raising kubelet eviction threshold (e.g., --eviction-hard), but pods still killed before kubelet action.

Question

Question

How do we align cgroup v2 memory.high enforcement with Kubernetes kubelet eviction behavior so pods aren't killed unexpectedly when node has free memory? What safe kernel or kubelet changes reduce premature per-cgroup OOMs?

COMMUNITY RESPONSES

Verified community troubleshooting

1 reply
0
oliverops Answer
user
Posted 4w ago • 0 confirmations

Start by increasing the container memory limit for one affected pod to provide headroom and rerun the job — if OOMs stop, limits are the issue. While testing, inspect /sys/fs/cgroup/.../memory.current and memory.high for the pod to confirm kernel enforcement. If kernel kills still occur before kubelet evicts, raise kubelet memory eviction thresholds slightly earlier so kubelet can act first. Do the change on a single node, validate no node-wide instability, then roll out. If unsure, collect cgroup and kubelet logs and escalate to platform team rather than disabling kernel cgroup controls.

Showing 1 of 1 community responses
AI DIAGNOSTICS

Incident analysis

Updated 4w ago• Trouble ID

Most likely causes

Per-cgroup memory.high or memory.max set too low relative to workload bursts, causing kernel to kill or throttle before kubelet evictions trigger. 85%
Kubelet eviction thresholds configured only at node level; mismatch with cgroup v2 enforcement semantics leading to race between kernel and kubelet. 70%
Application memory spikes (native allocations, thread stacks) exceed container memory limits unexpectedly; limits too tight. 60%

Summary

With cgroup v2 the kernel enforces memory.high and memory.max per-cgroup; when a container exceeds memory.high the kernel may throttle and if memory.max is hit it will kill processes. Kubelet's eviction logic operates at node level (memory.available, pressure) and may not catch per-cgroup enforcement. Causes include too-tight container memory limits, memory.high defaulting to limit or being derived from limit, or kernel-level cgroup settings (e.g., memory.swap.max) enforcing kills before kubelet can respond. Also pod workloads may burst above set limits (worker threads, native libraries).

Suggested Fixes

Diagnostic step 1
Reproduce under controlled load and monitor per-cgroup metrics: cat memory.current and memory.high in /sys/fs/cgroup/<kubepods>/... for affected pod cgroups.
Diagnostic step 2
Increase pod memory limits (and requests) to accommodate peak allocations, test workload; prefer headroom for native/library spikes.
Diagnostic step 3
Adjust kubelet eviction thresholds to be more aggressive earlier (e.g., higher memory.available watermark) so kubelet can evict before kernel kills. Test changes on one node first.

Continue troubleshooting

Matched from the title, description and tags