Kubernetes
A busy-spinning pod needs what a busy-spinning process on a VM needs: a whole core per busy thread, interrupts elsewhere, no page faults. Kubelet has to be told to give it that. The settings below apply to any low-latency pod; the node examples are EKS on Amazon Linux 2023 with self-managed nodes.
Terms: deployment glossary.
The kubelet and pod settings are the same on x86 (c7i) and Graviton
(c8g, c9g). Graviton’s kernel arguments: hosts.
Latency checklist
Use a dedicated node pool, tainted so only latency pods land there (keep other pods in check).
Node (kubelet and host):
- SMT off on x86, so one Kubernetes CPU is one physical core, the same as on Graviton (SMT off).
cpuManagerPolicy: staticwithfull-pcpus-only: "true": Guaranteed pods get whole cores of their own.reservedSystemCPUs: the housekeeping cores, the same ones the kernel’s boot line leaves out of isolation.topologyManagerPolicy: single-numa-node: a pod’s CPUs and devices on one NUMA node.- No CPU quota on the latency containers: kubelet 1.33 or later (the labs
ran 1.36),
cpuCFSQuotaleft at its defaulttrue. Do not setcpuCFSQuota: false: it removes every pod’s CPU limit on the node (why). - The host settings under the kubelet: isolated cores, interrupts on housekeeping, transparent hugepages off, hugepages (hosts).
Pod:
- Guaranteed QoS: requests equal limits for every resource, in every container.
- A whole-number CPU request on every busy-spinning container. With SMT off, one CPU is one core.
- Each busy thread pinned to its own core from the pod’s cpuset, under
SCHED_OTHER(SCHED_FIFO: settings). - On CRI-O only: the annotations in No CPU quota. containerd (EKS, k3s) ignores them.
Check:
- At start: call ergon-tune’s
t9_cpu_quotabefore your loop; T9 warns about a CPU quota. - While it runs:
nr_throttledstays flat (verify). In your own loop, call ergon-tune’sThrottleWatch::checkfrom housekeeping.
Nodes
Kubelet gives Guaranteed pods whole cores of their own (the static CPU
manager) and keeps a pod’s CPUs and devices on one NUMA node (the topology
manager). The EKS node’s NodeConfig, with $reserved the housekeeping
CPUs (0 on a c7i.4xlarge: one CPU is one physical core, because SMT is
off):
apiVersion: node.eks.aws/v1alpha1
kind: NodeConfig
spec:
cluster:
name: $cluster
apiServerEndpoint: $endpoint
certificateAuthority: $ca
cidr: $cidr
kubelet:
config:
cpuManagerPolicy: static
cpuManagerPolicyOptions:
full-pcpus-only: "true"
reservedSystemCPUs: "$reserved"
kubeReservedCgroup: ""
systemReservedCgroup: ""
topologyManagerPolicy: single-numa-node
topologyManagerScope: pod
memoryManagerPolicy: None
full-pcpus-only: whole physical cores, never one hyperthread shared with another pod. With SMT off it is a safety net.kubeReservedCgroupandsystemReservedCgroupare emptied because kubelet rejectsreservedSystemCPUswhile they are set.memoryManagerPolicy: None: ac7i.4xlargehas one NUMA node. On a multi-socket type, revisit it.cpuCFSQuotais not set: it staystrue, so every pod keeps its CPU limit. The kubelet drops the quota itself on a container with exclusive CPUs (No CPU quota).
What the node needs before the kubelet starts:
| when | what |
|---|---|
| once, then one reboot before kubelet | kernel command line: nosmt, every CPU but the reserved core isolated, interrupts on that core, no C-state cap (evidence), transparent_hugepage=never, 2 MiB hugepages, so kubelet’s first start advertises hugepages-2Mi |
| every boot, before kubelet | interrupts on housekeeping, re-pinned on each link event; irqbalance, KSM, NUMA balancing off; THP off; rmem_max/wmem_max 16 MiB; Aeron’s directory on a sized hugetlbfs |
Leave clocksource to the kernel. A forced clocksource=tsc tsc=reliable
turns the kernel’s TSC checks off: use it only on bare metal, after the TSC
has been measured as the same across cores against a PTP/PHC reference.
Never on a VM.
Kubelet’s reserved CPUs and the kernel’s housekeeping CPUs are the same set: interrupts and system daemons stay off the pods’ cores. Label and taint the dedicated nodes (keep other pods in check).
SMT off
SMT (hyper-threading) runs two logical CPUs on one physical core. They share
the core’s execution resources: a pod with cpu: 1 shares a core with its
twin, and its latency follows what the twin does. Turn SMT off on x86 latency nodes, so
one Kubernetes CPU is one physical core, as on Graviton, which has no SMT.
| where | how |
|---|---|
| EC2, virtual machine | the node group’s launch template: CpuOptions with CoreCount (the type’s default core count) and ThreadsPerCore: 1. Both fields are required; there is no extra charge. Not on bare metal (EC2 takes no CPU options there). EC2 will not change threads per core on T2, C7a, M7a, R7a, Apple silicon Mac or Graviton. C7a, M7a, R7a and Graviton already run one thread per core |
| EC2 bare metal, self-managed | the kernel’s nosmt on the boot line. Before the kubelet’s first start, writing off to /sys/devices/system/cpu/smt/control works too: write it, then delete /var/lib/kubelet/cpu_manager_state (the CPU manager state lists the old CPUs, and the kubelet crash-loops without the delete) |
| self-managed, k3s | nosmt on the kernel command line |
- With
ThreadsPerCore: 1the instance runs half its usual vCPU count (ac7i.4xlarge: 8 cores, 8 vCPUs, not 16). Size pods and quotas for cores. thread_siblings_liststill lists the offline twin. Name one CPU per core (the lowest id) inreservedSystemCPUsand in kernel arguments.- Check it on the node:
/sys/devices/system/cpu/smt/activereads0.
Pods
- Guaranteed QoS with whole cores: requests equal to limits on every resource, and a whole-number CPU request.
- Pin each busy thread to its own core from the pod’s cpuset. Read it from
Cpus_allowed_listin/proc/self/status; in a privileged container/sys/fs/cgroup/cpuset.cpus.effectivelists every host CPU. One logical CPU per physical core, and Aeron’s client conductor off the busy cores. - Hugepages as a resource (
hugepages-2Mi), Aeron’s directory from the node’s hugetlbfs as ahostPath, andAERON_CLIENT_PRE_TOUCH_MAPPED_MEMORY=trueon clients. - Handle SIGTERM. Kubelet stops a pod with it; a PID 1 with no handler ignores it until SIGKILL, closing nothing.
- Privileged only where needed: a kernel-bypass driver that maps the NIC and locks hugepages. A client that only reaches the media driver through Aeron’s directory is not.
hostNetwork: truetakes a kernel-UDP pod off the pod network’s virtual interface. Not measured here.
Keep other pods in check
A dedicated node pool only works if nothing else lands there.
- Taint the latency nodes (
NoSchedule) and let only latency pods and the DaemonSets that must run there tolerate it: the CNI, kube-proxy, the node agent, a log collector, the media driver. Everything else stays off. - A
LimitRangeper namespace with a default CPU request and limit for containers, and aResourceQuotafor the namespace. An unlabelled pod then cannot ask for half a node. - Small CPU requests and limits on the DaemonSets that stay (log collectors, a metrics agent): a limit keeps a burst off the latency cores. Give both; a limit with no request still lets them burst up to it.
PriorityClass: one high class for latency pods, a low one for the rest. A latency pod then preempts, not the other way round.- Kubelet 1.33 or later with the static CPU manager: only a Guaranteed whole-CPU container loses its quota; everything else keeps its CPU limit (No CPU quota).
strict-cpu-reservation (kubelet policy option, GA in 1.35): by default
the shared CPU pool includes reservedSystemCPUs, so a Burstable pod or a
fractional sidecar can run on the reserved CPUs. strict-cpu-reservation: "true" keeps everything that was not given those CPUs off them. Use it only
when nothing but the system (and threads you pin there yourself) may use
them: it breaks anything that needs the shared pool by default, such as a
fractional sidecar in a latency pod or a helper thread left on the shared pool. The
shared-CPU NRI plugin (ghcr.io/mimran1980/ergon-shared-cpus:0.1.6; chart oci://ghcr.io/mimran1980/charts/ergon-shared-cpus version 0.1.6)
lends shared CPUs from reservedSystemCPUs to a pod’s helper threads and expects the
default, so leave strict-cpu-reservation off while using it.
No CPU quota
- A CPU quota (Linux’s CFS bandwidth control) lets a container’s threads run for at most the quota in each 100 ms period. Kubernetes sets it from the container’s CPU limit.
- A busy-spinning thread uses its core all the time, so it runs at the cap. When the container’s other threads push it over, the kernel stops every thread in it until the period ends: a stall of milliseconds.
- A pod has a quota of its own too: the sum of its containers’ limits. From
inside a container, only
cpu.stat.localshows it.
cpu.max holds two numbers in µs: the quota, then the period. max means no limit. In each period the kernel lets all of the cgroup’s threads together run for at most the quota; both cases below use a 100 000 µs (100 ms) period.(50 ms per period)
(200 ms per period)
ThrottleWatch::check, from housekeeping every few seconds, reads cpu.stat.local first and cpu.stat only when that grew, and reports “throttled in {t} of the last {p} periods”.The pod has a quota of its own, the sum of its containers’ limits. A container cannot see its pod’s cgroup: only
cpu.stat.local (Linux 6.6 and later) shows the pod’s quota stopping it.cpu.max = maxNo budget, so the spinner never stops. Per the Kubernetes docs, kubelet 1.33+ drops the quota for a container with exclusive CPUs (static CPU manager, a Guaranteed pod, a whole-number CPU request). Never
cpuCFSQuota: false: it is node-wide.cpu.max = 50000 100000 · 0.5 CPU per 100 ms periodnr_periods 3, nr_throttled 3, throttled_usec about 150000.cpu.max = 200000 100000 · 2 CPUs per 100 ms periodnr_periods 3, nr_throttled 1, and throttled_usec grows by the stopped time.What the kubelet writes:
| case | container cpu.max | pod cpu.max |
|---|---|---|
default (cpuCFSQuota: true), no exclusive CPUs | limit × period: 200000 100000 for 2 CPUs | the sum of the containers’ limits |
| kubelet 1.33+, a container with exclusive CPUs | max | max when any container has exclusive CPUs |
| a sidecar with a fractional CPU in that pod | still capped: 50000 100000 | max |
cpuCFSQuota: false (the whole node: do not) | max | max |
- Exclusive CPUs need all three:
cpuManagerPolicy: static, a Guaranteed pod, and a whole-number CPU request on the container. Kubelet 1.33 is the first that then drops the quota. - Do not set
cpuCFSQuota: false. It is node-wide: it removes the CPU limit of every pod there, log collectors and system pods too, and they then run unlimited on the shared CPUs. The kubelet’s own behaviour above is enough, and it only touches the containers with exclusive CPUs. - Kubelet 1.31 and 1.32 (EKS extended support) always set the quota. Use 1.33 or later (the EKS verification ran 1.36).
- Changing
cpuManagerPolicy: drain the node, stop the kubelet, delete/var/lib/kubelet/cpu_manager_state, start the kubelet. Without the delete, the kubelet crash-loops.
The kubelet config file:
apiVersion: kubelet.config.k8s.io/v1beta1
kind: KubeletConfiguration
cpuManagerPolicy: static
cpuManagerPolicyOptions:
full-pcpus-only: "true"
reservedSystemCPUs: "0" # the housekeeping cores (one CPU is one core)
topologyManagerPolicy: single-numa-node
# cpuCFSQuota is not set: it stays true, so every pod keeps its CPU limit.
EKS, Amazon Linux 2023: nodeadm writes its defaults to
/etc/kubernetes/kubelet/config.json and spec.kubelet.config to the
drop-in /etc/kubernetes/kubelet/config.json.d/40-nodeadm.conf, and runs
the kubelet with --config-dir on that directory, so the kubelet merges
the drop-in over the file. Put the NodeConfig in the launch template’s
user data, as a MIME part with Content-Type: application/node.eks.aws.
The full one, with the cluster fields, is in Nodes. The
shared-CPU plugin reads both for its hot-pod check with
hostContract.kubeletConfigDir:
EKS install.
apiVersion: node.eks.aws/v1alpha1
kind: NodeConfig
spec:
kubelet:
config:
cpuManagerPolicy: static
cpuManagerPolicyOptions:
full-pcpus-only: "true"
reservedSystemCPUs: "0"
EKS, Bottlerocket: in the user data (TOML). Reboot after changing the
policy. It has reserved-cpus and cpu-manager-policy-options too, but no
feature gates. Leave cpu-cfs-quota-enforced at its default true.
[settings.kubernetes]
cpu-manager-policy = "static"
k3s: in /etc/rancher/k3s/config.yaml, or as a KubeletConfiguration
drop-in under /var/lib/rancher/k3s/agent/etc/kubelet.conf.d/.
kubelet-arg:
- "cpu-manager-policy=static"
- "reserved-cpus=0"
CRI-O (OpenShift): the kubelet settings above are enough. CRI-O can also
drop the quota per pod, but only with the high-performance runtime class
(OpenShift’s Node Tuning Operator makes performance-<profile>), a
Guaranteed pod and whole CPUs. containerd ignores these annotations, so they
are safe in a shared manifest.
metadata:
annotations:
cpu-quota.crio.io: "disable"
cpu-load-balancing.crio.io: "disable"
irq-load-balancing.crio.io: "disable"
spec:
runtimeClassName: performance-<profile>
Verify
On the node:
kubectl get node <node> -o jsonpath='{.status.nodeInfo.kubeletVersion}' # 1.33 or later
kubectl get --raw /api/v1/nodes/<node>/proxy/configz \
| jq '.kubeletconfig | {cpuCFSQuota, cpuManagerPolicy, cpuManagerPolicyOptions, reservedSystemCPUs}'
cpuCFSQuota reads true (or is absent: that is the default).
In the pod:
cat /sys/fs/cgroup/cpu.max # max 100000
grep throttled /sys/fs/cgroup/cpu.stat
cat /sys/fs/cgroup/cpu.stat.local # Linux 6.6+: counts the pod's quota too
nr_throttledandthrottled_usecstay flat while the pod runs. Read them twice, a minute apart.- In Prometheus, cAdvisor’s
container_cpu_cfs_throttled_periods_totalstays flat. - ergon-tune: call T9 at start and
ThrottleWatch::checkfrom your loop’s housekeeping.
Checks inside a pod
A pod sees the host’s CPU, interrupt and memory files but its own network
namespace. ergon-tune reports the network settings it
cannot read there as unknown, never as a warning. Run the NIC checks on the
node, or in a pod on the host’s network. T9 reads the container’s own cgroup;
the pod’s quota shows only in cpu.stat.local (verify).
Under ERGON_HOST_CHECKS=require, a caller refuses a stock
static-CPU-manager pod: K2 cannot prove exclusive CPUs from the kubelet’s
cpuset, so it reports unknown. An isolated cpuset partition, as the
latency pods plugin
grants, passes it (ergon-tune).