Skip to content

hetzner-mgmt: Talos's OOM controller

Kind: reference and how-to (runbook), task #2547

Every hetzner-mgmt node runs Talos's userspace OOM controller. When a node runs short of memory, it kills one pod (the whole pod cgroup, sandbox included). The defaults chose the wrong pod: on 2026-11-04 an agent run grew to 3.3 GiB on worker-2, and the controller killed Prometheus, Grafana, tasks-prod-db-1, Gitea, Cilium, the hcloud CSI controller and keycloak-db-1. It never touched the run (incident report operations/incidents/2026-11-04-worker-2-pods-killed-talos-oom-controller.md, #2540). oom-config.yaml in the 1-bootstrap stage sets an OOMConfig so the controller kills the pod that grew. The webshop cluster runs the same Talos and carries the same document; see The webshop cluster (#2550).

How the controller works

runtime.OOMController in machined, on by default in the Talos v1.13.2 the nodes run. The source is controllers/runtime/oom.go, controllers/runtime/internal/oom/oom.go and the defaults in constants.go.

  • Every 500 ms it reads memory pressure (PSI) and evaluates the trigger expression.
  • When the trigger is true, it scores every cgroup under kubepods/{besteffort,burstable,guaranteed}, podruntime and system with the ranking expression. Then it writes 1 to cgroup.kill of the highest score. There is no floor: it always kills the top score, even 0 or a negative one, and a tie is broken by Go map order, that is, at random.
  • The ranking sees only class (Besteffort, Burstable, Guaranteed, Podruntime, System), path (/sys/fs/cgroup/kubepods/burstable/pod<uid>), and memory_current, memory_peak and memory_max (optional unsigned bytes). It sees no namespace, label or request, so it cannot pick the agent runners by name or rank by use over request.
  • It keeps the last 50 actions in memory (talosctl get oomactions), lost on reboot. Its log lines (OOM controller triggered, Sending SIGKILL to cgroup, victim processes:) go to the controller-runtime service log, not machined.

What was wrong with the defaults (Talos v1.13.2)

  • Ranking. memory_max.hasValue() ? 0.0 : … gives 0 to every pod that has a pod-level memory.max. The kubelet sets one only when every container and init container has a memory limit, which is true of the agent runners and the act runners. So the pods that grow by gigabytes during a run or CI job are never chosen. The ones ranked are the largest pods with an unlimited container: Prometheus, Grafana, Cilium, and Gitea and the CNPG clusters through their init containers. On 2026-11-04 at 20:10 the default would have killed cilium first on worker-1 and worker-3, and Prometheus on worker-2.
  • Trigger. The first clause, system or podruntime stalling, has no cooldown. It fired every 0.5–2 s while the PSI averages stayed high, and seven pods were killed in five seconds. The second clause, memory_full_avg10 > 75.0 over the whole node, has a 10 s cooldown, so it cannot explain kills 2 to 7. Talos v1.14 dropped that second clause because pods with memory limits that do heavy IO raise it with memory to spare (siderolabs/talos#13895), and added a 5 s cooldown to the first.

The configuration

apiVersion: v1alpha1
kind: OOMConfig
triggerExpression: |-
  multiply_qos_vectors(d_qos_memory_full_total, {System: 8.0, Podruntime: 4.0}) > 3000.0 &&
    multiply_qos_vectors(qos_memory_full_avg10, {System: 1.0, Podruntime: 1.0}) > 5.0 &&
    time_since_trigger > duration("5s")
cgroupRankingExpression: |-
  class == Podruntime || class == System ? -1.0 :
    {Besteffort: 1.0, Burstable: 0.5, Guaranteed: 0.1, Podruntime: 0.0, System: 0.0}[class] *
      double(memory_current.orValue(0u))
  • Ranking: the largest pod first, limited or not. A pod that pushes a node short of memory is, by then, the largest on it. BestEffort still counts double Burstable, as in the default. Guaranteed pods come after them, ordered by size rather than at random. podruntime (kubelet, containerd) and system score -1, below every pod, so they are never chosen while a pod is left.
  • Trigger: Talos v1.14's default. It must be set: in v1.13.2, OOMConfig.TriggerExpression() tests whether the ranking is empty, so a document with only a ranking hands the controller an empty trigger. Evaluating that panics with expression is not set on every tick. Pinning v1.14's default adds the 5 s cooldown, so after the runner is killed its memory is freed before the next check. It also drops the clause that can fire with memory to spare.
  • Patch both expressions together. A patch that merges into an existing OOMConfig document without them drops them (siderolabs/talos#14584), and v1.13.2 then fails as above.

What it does to runs and CI jobs

When a run or CI job pushes its node short of memory, its pod is killed instead of the platform's.

  • An agent runner pod is killed whole, with its sidecars, and restarts. The run is lost and shows in Taskbase as a failed or lost run, which triage requeues or, after the same failure twice, gives to the owner. If the pod restarts within about two minutes of a Codex token refresh, the login needs step 8 of Run a runner in the cluster again.
  • An act runner pod is killed with its dind sidecar, and every job in it fails. Rerun them.
  • Without a run or job, the largest pod is killed as before: Prometheus on worker-2, then Grafana. A database or Gitea is chosen only once it is the largest pod on its node.

Next to the kubelet's soft eviction

The workers also get a kubelet soft-eviction threshold (hetzner-mgmt worker memory eviction, #2502). The two are separate lines of defence and do not replace each other:

  • The kubelet acts first, when memory falls slowly. Below 2 GiB of its memory.available for 10 s, it evicts the pod furthest over its memory request, the ci-runner PriorityClass first. It checks every 10 s, so it misses a fall that is too fast: worker-1 at 13:55 on 2026-11-04 fell below the threshold only as it stalled.
  • The OOM controller is the backstop. It reads PSI every 500 ms and acts once the system or podruntime is already stalling, on every node, the control plane included, which has no soft threshold.
  • They choose by different rules. The kubelet reads requests and priorities; the controller sees only sizes. A run that grows is usually both: on worker-2 at 18:42, emilia-container-agent was the largest pod and 1.7 GiB over its 1.5 GiB request.
  • They are applied separately. The eviction is under machine.kubelet on the workers and restarts the kubelet; the OOMConfig is its own document on all four nodes and needs no reboot. Either can go first, and each dry run shows only its own change.

Evidence

Checked against Talos v1.13.2's own pkg/machinery: generate, configpatcher, configloader and the controller's CEL environments, the way talosctl gen config --config-patch and talosctl patch machineconfig use them.

  • oom-config.yaml patches a generated worker config, and the result validates. Patching it a second time keeps both expressions. A $patch: delete patch removes it.
  • A document with only a ranking reproduces the v1.13.2 panic: expression is not set.
  • The default ranking, fed the pod cgroup memory of worker-2 at 18:42:30, reproduces the incident's kill order: Prometheus 411, Grafana 214, Gitea 143, tasks-prod-db-1 140, Cilium 108, CSI controller 100, keycloak-db-1 70; the runner scores 0. The new ranking puts emilia-container-agent first at 1698 (3395 MiB × 0.5).
  • With only limited pods and podruntime/system left, every default score is 0 and the choice is random. The new ranking picks the largest pod.
  • The trigger is true while system is stalled, false 0.5 s after a kill and true again after 6 s. It is false when only the overall memory_full_avg10 is high.

The mechanism of 2026-11-04 is still unconfirmed on the node: #2546 reads the action log.

Options not taken

  • Raise the runners' requests (#2407). That places runs better, but the ranking never reads requests, and the owner's capacity decision #2409 stands. It stays a separate decision.
  • Limit the init containers of Gitea and the CNPG clusters. This only gives those pods a memory.max, so they score 0 too. The choice then falls on Cilium and Prometheus, or, once every pod is limited, on a random cgroup, podruntime included.
  • Weight the runner pods by name. The ranking sees only a pod's UID, which changes with every pod.
  • Turn the controller off (a trigger of false). Without it, a stalled node waits for the kernel OOM killer or stalls for minutes, as worker-3 did on 2026-11-04.

Apply it (owner, #2549)

terraform apply does not apply it: the stage applies machine config only when a server is created, so oom-config.yaml reaches a new node through talosctl gen config and a running node only through talosctl patch machineconfig. The controller reads the machine config live, so the patch should need no reboot; --mode no-reboot refuses it rather than rebooting if it did. Read the OOM action log for #2546 first.

cd terraform/environments/hetzner-mgmt-cluster/1-bootstrap   # on main, after the merge
T="talosctl --talosconfig ./talosconfig --endpoints 78.47.74.196"

# 1. Dry run on worker-2: the diff adds only the OOMConfig document.
$T --nodes 10.0.0.21 patch machineconfig --patch @oom-config.yaml --mode no-reboot --dry-run

# 2. Apply it to worker-2, then check it (below), then 10.0.0.20, 10.0.0.22 and 10.0.0.10,
#    one node at a time.
$T --nodes 10.0.0.21 patch machineconfig --patch @oom-config.yaml --mode no-reboot

Check each node. The machine config holds the cluster secrets, so print only the OOMConfig document:

$T --nodes 10.0.0.21 get machineconfig -o yaml | grep -A12 'kind: OOMConfig'
# Expect both expressions as in oom-config.yaml.
$T --nodes 10.0.0.21 logs controller-runtime | grep -iE 'oom|panic' | tail -n 20
# Expect no "cannot evaluate OOM trigger expression", "expression is not set" or panic after the patch.
kubectl --context admin@mgmt-cluster get nodes   # all Ready

Done when all four nodes show the document and none logs an error. The next time the trigger fires, $T --nodes <ip> get oomactions -o yaml shows the killed cgroup and its score.

Roll back a node to the Talos defaults:

printf 'apiVersion: v1alpha1\nkind: OOMConfig\n$patch: delete\n' > /tmp/oom-config-delete.yaml
$T --nodes <ip> patch machineconfig --patch @/tmp/oom-config-delete.yaml --mode no-reboot

The webshop cluster

webshop runs the same Talos v1.13.2 on one cx33 node (8 GB) and gets the same document: 2-cluster/oom-config.yaml, passed to the module's extra_patches in the 2-cluster stage. Keep it the same as hetzner-mgmt's (#2550).

Why the same ranking fits

The node's pods on 2026-11-04 (pod cgroup memory from the cluster's Prometheus, 7 days of data):

  • Fully limited, so the default scores them 0: the shop's web (two pods, 384 MiB each), frontend and worker (256 MiB), Prometheus (680 MiB, using 662), and the small operators (cert-manager, CoreDNS, External Secrets, Flagger, the CNPG operator, the Barman Cloud Plugin).
  • Ranked by the default: kube-apiserver (1898 MiB now, 2584 at most), Cilium (252), shop-demo-db-1 (215; its plugin-barman-cloud sidecar has no limit), the hcloud CSI controller, Hubble, the Flux controllers, MetalLB.
  • The node had at least 2.5 GiB available in the 7 days.

The scores, MiB-weighted, from Talos's own CEL environment (celenv.OOMCgroupScoring):

Case Default (top four) oom-config.yaml (top four)
As measured kube-apiserver 949, Cilium 126, shop-demo-db-1 108, CSI controller 94 kube-apiserver 949, Prometheus 331, Cilium 126, shop-demo-db-1 108
Limited pods at their limits unchanged: the pods that grew score 0 kube-apiserver 949, Prometheus 340, web 192, web 192
  • The first kill is the same: kube-apiserver is the largest pod and has no limit, so either ranking chooses it first. The kubelet restarts it as a static pod; the shop keeps serving while the API is down.
  • After it, the pods that grew go first. The default goes on to Cilium and the shop database, however much the limited pods have grown. With the document, Prometheus and the shop pods come before them; web has two replicas, the database one instance. podruntime and system are never chosen.
  • The cooldown counts most on one node. Without it, a burst like hetzner-mgmt's seven kills in five seconds takes kube-apiserver, Cilium, the database and the CSI controller together: the whole cluster at once.
  • One document for both clusters, at the same Talos version, with one check on a Talos upgrade.

Apply it (owner)

The module passes the machine config as the server's user_data, and the hcloud provider replaces a server whose user_data changes. The module therefore ignores later user_data changes: the document reaches a server created from now on, and the running node only through talosctl patch machineconfig. A Terraform Apply - Webshop Cluster run after the merge plans no change to the server; if its plan shows hcloud_server.controlplane[0] replaced, stop it.

cd terraform/environments/hetzner-webshop-cluster/2-cluster   # on main, after the merge
terraform init && terraform output -raw talosconfig > talosconfig && chmod 600 talosconfig
T="talosctl --talosconfig ./talosconfig"   # its endpoint and node are the one server

# 1. Dry run: the diff adds only the OOMConfig document.
$T patch machineconfig --patch @oom-config.yaml --mode no-reboot --dry-run
# 2. Apply it.
$T patch machineconfig --patch @oom-config.yaml --mode no-reboot

Check it as for hetzner-mgmt: $T get machineconfig -o yaml | grep -A12 'kind: OOMConfig' shows both expressions, $T logs controller-runtime | grep -iE 'oom|panic' shows no error after the patch, and kubectl --context webshop get nodes is Ready. Roll back with the same $patch: delete patch as above. Delete the local talosconfig afterwards.

On a Talos upgrade

The trigger here is Talos v1.14's default, pinned. From v1.14, TriggerExpression() falls back to the default when it is unset, so after that upgrade, compare the new default with this one, and check that the ranking variables have not changed. See Talos OS Upgrade. The webshop cluster carries the same document, so check and change both files together.