Stop paying for the CPU your pods leave idle
Last year somebody set cpu: 1 on a Deployment. It felt safe. Today the process uses about a third of that core. The scheduler doesn't care. It holds the whole core on the node for every replica: at 3 a.m., all weekend, through every quiet hour of the month. Two thirds of that core sits reserved, doing nothing. For years the fix meant restarting the pod, so nobody bothered. That excuse is gone.…
A Kubernetes Deployment was inadvertently configured with a CPU request of 1 core. The scheduler reserved a third of that core for all replicas, leaving two thirds idle 24/7. The solution is now available in Kubernetes 1.33 and above via the In-place resize feature. Attune, a Kubernetes operator, automates this process by adjusting CPU requests in-place, freeing up reserved resources.
Attune reads metrics from Prometheus, calculates optimal CPU and memory requests, and then applies them to the target pods. It works by lowering the CPU request, keeping the existing connections, and giving the node back its reserved reservation. To install Attune, you need Kubernetes version 1.32 or newer. The policy is defined using a YAML file that specifies the target Deployment, metrics source (Prometheus), and target CPU and memory requests.
The policy is applied using the kubectl apply command. After the policy is in place, you can view the recommended CPU requests and estimated savings using the kubectl attune recommendations and kubectl attune savings commands. These commands show the difference between the current CPU request and the recommended value, along with an estimate of the monthly savings.
If a resized container is OOMKilled within 5 minutes, Attune reverts to the previous request. However, if the policy is set to "Recommend," it only suggests the new values without making any changes. This allows for manual review before applying the changes. It's important to note that an HPA (Horizontal Pod Autoscaler) that scales on CPU utilization could potentially negate the savings if the request is lowered.
To prevent this, set the HPA target with the annotation attune.io/auto-tune: true and ensure that the minimum allowed CPU request is high enough to avoid further reductions.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.