Nitin Ware detailed how to use Linux Pressure Stall Information to measure CPU waiting and diagnose resource contention in Kubernetes workloads.
What it does
Linux Pressure Stall Information (PSI) measures how much of the time at least one task was ready to run but waiting for CPU. Nitin Ware explains that CPU utilization does not show whether workloads are waiting for CPU time, whereas PSI measures that waiting.
Before you start
The setup requires a Linux host with cgroup v2, a kernel with PSI enabled, Docker, kind, kubectl, and jq, with at least 4 CPUs. On macOS, Colima can run Docker Engine in a Linux VM.
Steps
Step 1: Check cgroup v2 and PSI on the host by verifying the expected lines using stat and cat commands.
Step 2: Create a two-node cluster with kind using a custom configuration file and restrict node CPUs with Docker.
Step 3: Install metrics-server for kubectl top and configure it with the insecure TLS flag for local testing.
Step 4: Apply deployment configurations and read CPU pressure data using the kubelet Summary API.
What the company says
Writing on the Kubernetes Blog, Nitin Ware stated that checking CPU pressure alongside utilization helps explain performance problems where traditional metrics fall short.
What to do
- Check cgroup v2 and PSI on the host.
- Create a two-node cluster using kind and pin nodes to separate CPUs.
- Read CPU pressure using the kubelet Summary API.
Key facts and where they come from
- Kubernetes exposes PSI through the kubelet starting from version v1.36.
Kubernetes exposes PSI through the kubelet, and the metrics are stable from Kubernetes v1.36.
- Test runs showed identical CPU utilization of 2001m with drastically different CPU pressure readings.
CPU pressure was 0.33% in the first run and 99.63% in the second.
