Skip to main content
Linux Performance Tuning for Containers and Kubernetes Nodes

Linux Performance Tuning for Containers and Kubernetes Nodes

KU
· Founder & Chief Editor
• 8 min read•Updated •

Container performance problems usually live in the node kernel, not your app. Here is what we tune, why, and how we measure before touching anything.

Key takeaways

  • Start with Pressure Stall Information and the CFS throttling ratio, because they show whether a node is short on CPU, memory or I/O and whether CPU limits are freezing pods.
  • Fix limits and memory first, then conntrack and sysctls baked into the node image, and save NUMA pinning and hugepages for the few pods that measurably need them.

Tune a Kubernetes node in this order: read Pressure Stall Information (/proc/pressure/*) to find the starved resource, check the CFS throttling ratio for pods with CPU limits, fix limits and memory, then raise conntrack and sysctl limits through your node image. Save NUMA pinning and hugepages for the latency-critical pods that measurably need them.

Verified againstChecked against official docs

Kubernetes 1.37 (1.37.1), Linux 7.3 docs, against the kubernetes.io CPU management, swap, sysctl and virtual IPs (kube-proxy) pages and the kernel.org PSI documentation. Checked October 2026.

Most "the app is slow" tickets that land on a platform team are not application bugs. They are the node kernel doing what it was told, which is wrong for a container workload: fresh node defaults are tuned for a general-purpose server, not forty pods sharing cgroups and a conntrack table. This is the checklist, in the order to run it.

One rule before any of it: measure first. Teams that double net.core.somaxconn everywhere because a blog said so spend a week wondering why nothing changed. Tune what the data points at.

Measure before you touch anything

Pressure Stall Information (PSI) is the fastest way to tell whether a node is starved for CPU, memory or I/O. It ships in the kernel and needs nothing installed.

Bash
cat /proc/pressure/cpu /proc/pressure/memory /proc/pressure/io     # node-wide
cat /sys/fs/cgroup/kubepods.slice/memory.pressure                 # all pods, cgroup v2

Per the kernel docs, the some line is the share of time at least one task was stalled on that resource, and avg10 averages it over the last 10 seconds (avg60 and avg300 give the trend). As a rule of thumb (not a documented threshold), anything consistently above 5-10% on CPU or memory means the node is the bottleneck, and now you know which resource to chase. The per-cgroup files (cpu.pressure, memory.pressure, io.pressure) need cgroup v2, which kubelet 1.35 and later require by default anyway (see the kubelet's cgroup v1 cutoff).

CPU: throttling is the silent killer

The single most common hidden problem is CFS quota throttling. When a pod has a CPU limit, the kernel enforces it as a quota per scheduling period (100ms by default). If the pod burns its quota in 40ms, it is frozen for the remaining 60ms of that period, even when the node is 90% idle. Latency-sensitive services fall off a cliff and the CPU graph looks fine.

Check it straight from the cgroup, or in Prometheus:

Bash
cat /sys/fs/cgroup/kubepods.slice/kubepods-burstable.slice/<pod-slice>/cpu.stat
# watch nr_throttled and throttled_usec climbing over time
PromQL
rate(container_cpu_cfs_throttled_periods_total[5m])
  / rate(container_cpu_cfs_periods_total[5m])

If that ratio is meaningfully above zero for a slow service, the limit is the problem. Options, in order of preference: raise the limit, remove the limit and rely on requests for scheduling, or for genuinely latency-sensitive workloads give the pod whole CPUs with the static CPU Manager policy so it stops sharing cores.

YAML
# /var/lib/kubelet/config.yaml (excerpt): pin Guaranteed pods to exclusive cores
cpuManagerPolicy: static
kubeReserved:
  cpu: "500m"
systemReserved:
  cpu: "500m"

The kubernetes.io docs are specific about two requirements: the kubelet refuses the static policy without a CPU reservation greater than zero, and only containers in Guaranteed-QoS pods with integer CPU requests get exclusive CPUs. Requests, not limits, are what the scheduler packs against, so a node crammed to 100% of requests will show contention even without any single pod misbehaving.

Memory: limits, overcommit, and OOM

Memory has no equivalent of throttling. A container that hits its memory limit gets OOM-killed, full stop. Under cgroup v2 the kernel reclaims page cache first, and memory.pressure spikes before the kill, which is your early warning; reading memory PSI before the OOM killer covers the alerting side.

Kubernetes no longer demands swap be off, but the defaults are conservative (details in the questions below). For bursty workloads a little swap absorbs spikes that would otherwise kill a pod. We enable it cautiously and keep vm.swappiness low so the kernel treats it as a safety net, not a habit.

Bash
sudo sysctl -w vm.swappiness=10
sudo sysctl -w vm.overcommit_memory=1   # let the scheduler, not the kernel, gate memory

Watch container_memory_working_set_bytes against the limit, not RSS. Working set is the number the kubelet uses for eviction decisions and the one that tracks the OOM kill.

I/O and ephemeral storage

Container image layers, logs and emptyDir volumes all land on the node's ephemeral disk, and a single chatty pod can starve everyone else. On NVMe the none (or mq-deadline) scheduler usually beats anything fancier.

Bash
cat /sys/block/nvme0n1/queue/scheduler
echo none | sudo tee /sys/block/nvme0n1/queue/scheduler

Set ephemeral-storage requests and limits so a runaway log file gets the pod evicted instead of filling the root filesystem and taking the kubelet down with it. For write-heavy workloads, put container storage on its own ext4 or xfs volume.

Network: the limits nobody sets until they hit them

High-connection nodes hit two walls constantly. The first is the conntrack table. Every tracked connection consumes a slot, and when it fills you get silent packet drops and nf_conntrack: table full in dmesg.

Bash
cat /proc/sys/net/netfilter/nf_conntrack_count /proc/sys/net/netfilter/nf_conntrack_max

The second is the accept backlog and ephemeral port range for nodes that make lots of outbound connections. These are the sysctls we set on ingress and high-throughput nodes:

/etc/sysctl.d/90-k8s-network.conf
net.netfilter.nf_conntrack_max = 1048576
net.core.somaxconn = 32768
net.ipv4.ip_local_port_range = 1024 65535
net.ipv4.tcp_tw_reuse = 1

somaxconn only helps if the application actually passes a large backlog to listen(), so bumping it is necessary but not sufficient. If kube-proxy runs in iptables mode and you see connection setup latency at scale, move to nftables mode, not IPVS, which is deprecated (see below). The rule-level differences are in iptables vs nftables.

Sysctls that matter for containers

A handful of kernel limits are per-node and bite container workloads specifically. vm.max_map_count is the classic: Elasticsearch, and anything with a large mmap footprint, will refuse to start below 262144. fs.inotify limits get exhausted by nodes running many pods that each watch files.

/etc/sysctl.d/90-k8s-node.conf
vm.max_map_count = 262144
fs.inotify.max_user_instances = 8192
fs.inotify.max_user_watches = 524288
fs.file-max = 2097152

Do not hand-edit sysctl files on live nodes: the next node the autoscaler brings up won't have the change. Apply them through provisioning; Ansible is our default for the base image:

roles/k8s-node/tasks/sysctl.yml
- name: Container-node sysctls
  ansible.posix.sysctl:
    name: "{{ item.name }}"
    value: "{{ item.value }}"
    sysctl_set: true
    state: present
    reload: true
  loop:
    - { name: vm.max_map_count, value: "262144" }
    - { name: fs.inotify.max_user_watches, value: "524288" }
    - { name: net.core.somaxconn, value: "32768" }

For sysctls one workload needs, use pod-level securityContext.sysctls: per the kubernetes.io docs, safe sysctls are allowed by default and unsafe ones need --allowed-unsafe-sysctls on each kubelet. Or use a tuning operator such as the Node Tuning Operator with TuneD, so the setting travels with the node pool.

NUMA and hugepages for latency-sensitive pods

For workloads that genuinely care about tail latency (packet processing, some databases, in-memory caches), the last mile is topology: cross-NUMA memory access costs real nanoseconds. The kubelet Topology Manager with the single-numa-node policy keeps a pod's CPUs and memory on the same socket. Hugepages cut TLB misses for large memory footprints:

Bash
sudo sysctl -w vm.nr_hugepages=1024   # reserve 1024 x 2MB hugepages

Then request them like any other resource in the pod spec. This is not free complexity, so we only reach for it after PSI and throttling metrics say the ordinary tuning was not enough. For the provisioning side we lean on throughout, see configuring servers with Ansible.

Questions people ask

How do I know if a Kubernetes pod is CPU throttled?

Divide container_cpu_cfs_throttled_periods_total by container_cpu_cfs_periods_total over five minutes in Prometheus, or read nr_throttled and throttled_usec from the pod's cpu.stat file under /sys/fs/cgroup. A ratio meaningfully above zero on a slow service means its CPU limit is freezing it, even when the node itself is mostly idle. Raise or remove the limit and keep the request.

Should I enable swap on Kubernetes nodes?

Only deliberately. The kubelet refuses to start on a swap-enabled Linux node unless you set failSwapOn: false, and the default NoSwap behavior still gives pods no swap. With LimitedSwap, only Burstable pods can swap; Guaranteed, BestEffort and high-priority pods cannot. A small swap device with low vm.swappiness can absorb memory spikes, but it hides leaks if you stop watching PSI.

Should kube-proxy use IPVS or nftables?

Use nftables for new clusters. As of Kubernetes 1.37 the docs mark ipvs mode deprecated since v1.35, disabled by default from v1.40 and scheduled for removal in v1.43, and recommend nftables as the replacement, describing it as faster than both iptables and IPVS. It needs kernel 5.13 or later. The default is still iptables, so set the mode explicitly.

The call we'd make

Start every investigation at PSI and the CFS throttling ratio, because those two numbers explain most container performance complaints without guessing. Fix throttling and memory limits before you touch a single network sysctl. Bake the node-level sysctls into the image with Ansible or a tuning operator so they are boring and reproducible, plan the kube-proxy move to nftables before IPVS goes away, and save NUMA plus hugepages for the handful of pods that measurably need them. Tuning you cannot point at a metric is just cargo cult with root access.

Sources

Explore topics:KubernetesLinux
React
Share this post
Cite this article
Plain text

Kiril Urbonas (2025). Linux Performance Tuning for Containers and Kubernetes Nodes. DevOpsNess. Updated 2026-11-20. https://www.devopsness.com/blog/linux-performance-tuning-for-containers-and-kubernetes-nodes

Markdown

[Linux Performance Tuning for Containers and Kubernetes Nodes](https://www.devopsness.com/blog/linux-performance-tuning-for-containers-and-kubernetes-nodes) (Kiril Urbonas, DevOpsNess, updated 2026-11-20)

KU

Kiril Urbonas

Founder & Chief Editor

610 articles
View all articles by Kiril Urbonas

You might have missed

Evergreen posts worth revisiting.