<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Sebastien Tardif</title>
    <description>The latest articles on DEV Community by Sebastien Tardif (@sebtardif).</description>
    <link>https://dev.to/sebtardif</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F317294%2F99268483-f4fa-44bd-8b4a-7ae2cee80274.png</url>
      <title>DEV Community: Sebastien Tardif</title>
      <link>https://dev.to/sebtardif</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/sebtardif"/>
    <language>en</language>
    <item>
      <title>Stop paying for the CPU your pods leave idle</title>
      <dc:creator>Sebastien Tardif</dc:creator>
      <pubDate>Wed, 04 Nov 2026 22:30:57 +0000</pubDate>
      <link>https://dev.to/sebtardif/stop-paying-for-the-cpu-your-pods-leave-idle-2c67</link>
      <guid>https://dev.to/sebtardif/stop-paying-for-the-cpu-your-pods-leave-idle-2c67</guid>
      <description>&lt;p&gt;Last year somebody set &lt;code&gt;cpu: 1&lt;/code&gt; on a Deployment. It felt safe. Today the process uses about a third of that core.&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;For years the fix meant restarting the pod, so nobody bothered. That excuse is gone. In-place resize is on by default from Kubernetes 1.33 and generally available in 1.35. You lower the CPU request on a running container, the process keeps its connections, and the node gets the reservation back.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/attune-io/attune" rel="noopener noreferrer"&gt;Attune&lt;/a&gt; is a Kubernetes operator that does this for a fleet. It reads Prometheus, shows the estimate, and does not touch a pod until you say so. A bad size is put back. First you install it. Then you look. Then you cut.&lt;/p&gt;

&lt;h2&gt;
  
  
  Install
&lt;/h2&gt;

&lt;p&gt;Attune needs Kubernetes 1.32 or newer. On 1.32, in-place resize still needs the &lt;code&gt;InPlacePodVerticalScaling&lt;/code&gt; feature gate. Webhooks are on by default and need cert-manager. If you don't run it, add &lt;code&gt;--set webhooks.enabled=false&lt;/code&gt; to the Helm command.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;helm &lt;span class="nb"&gt;install &lt;/span&gt;attune oci://ghcr.io/attune-io/charts/attune &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--namespace&lt;/span&gt; attune-system &lt;span class="nt"&gt;--create-namespace&lt;/span&gt;
kubectl krew &lt;span class="nb"&gt;install &lt;/span&gt;attune
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Point a policy at the services you suspect. &lt;code&gt;Recommend&lt;/code&gt; only writes numbers.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;apiVersion&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;attune.io/v1alpha1&lt;/span&gt;
&lt;span class="na"&gt;kind&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;AttunePolicy&lt;/span&gt;
&lt;span class="na"&gt;metadata&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;api-services&lt;/span&gt;
  &lt;span class="na"&gt;namespace&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;production&lt;/span&gt;
&lt;span class="na"&gt;spec&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;targetRef&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;kind&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Deployment&lt;/span&gt;
    &lt;span class="na"&gt;selector&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;matchLabels&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
        &lt;span class="na"&gt;tier&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;api&lt;/span&gt;
  &lt;span class="na"&gt;metricsSource&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;prometheus&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;address&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;http://prometheus-server.monitoring:80&lt;/span&gt;
  &lt;span class="na"&gt;cpu&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;percentile&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="m"&gt;95&lt;/span&gt;
    &lt;span class="na"&gt;overhead&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;20"&lt;/span&gt;
    &lt;span class="na"&gt;minAllowed&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;1m"&lt;/span&gt;
  &lt;span class="na"&gt;memory&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;percentile&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="m"&gt;99&lt;/span&gt;
    &lt;span class="na"&gt;overhead&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;30"&lt;/span&gt;
    &lt;span class="na"&gt;minAllowed&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;4Mi"&lt;/span&gt;
  &lt;span class="na"&gt;updateStrategy&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Recommend&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;These are the defaults, written out so the knobs are visible. The policy covers every &lt;code&gt;tier: api&lt;/code&gt; Deployment in &lt;code&gt;production&lt;/code&gt;. CPU lands at the 95th percentile plus 20 percent headroom. That &lt;code&gt;"20"&lt;/code&gt; is a percentage, not 20 millicores. Memory gets the 99th percentile plus 30 percent.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;kubectl apply &lt;span class="nt"&gt;-f&lt;/span&gt; policy.yaml
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If Prometheus already has the history, the number shows up on the first pass. A brand-new series needs 48 samples at the default 5 minute step, about 4 hours. For a faster first look, set &lt;code&gt;minimumDataPoints: 12&lt;/code&gt; under &lt;code&gt;metricsSource&lt;/code&gt;. That is about 1 hour at the same step. Leave &lt;code&gt;queryStep&lt;/code&gt; at the default so it stays near your scrape interval. After the numbers look right, drop the field and use 48.&lt;/p&gt;

&lt;h2&gt;
  
  
  Look
&lt;/h2&gt;

&lt;p&gt;The number you came for is in these two commands:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;kubectl attune recommendations &lt;span class="nt"&gt;-n&lt;/span&gt; production
kubectl attune savings &lt;span class="nt"&gt;-n&lt;/span&gt; production
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;recommendations&lt;/code&gt; puts the live CPU request next to the recommended one. &lt;code&gt;savings&lt;/code&gt; prices that gap at built-in list rates, about $0.031 per core-hour. The monthly figure is an estimate.&lt;/p&gt;

&lt;p&gt;Here is the Deployment from the opening. Usage sits around a third of the request at the busy end, so this illustration recommends 400m: that level plus 20 percent. Memory is already at the recommendation, so the saving is the CPU column. These rows are not a cluster we measured. &lt;code&gt;F&lt;/code&gt; means the request is far above the recommendation.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ kubectl attune recommendations -n production
NAMESPACE    POLICY        WORKLOAD   CONTAINER   CPU REQ   CPU REC   MEM REQ   MEM REC   GRADE   CONFIDENCE / STATUS
production   api-services  api        app         1         400m      512Mi     512Mi     F       90.0%

$ kubectl attune savings -n production
NAMESPACE    NAME          CPU SAVED   MEMORY SAVED   % SAVED   EST. MONTHLY
production   api-services  600m        -              60%       $13.58

             TOTAL         600m        0B             60%       $13.58
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;600m&lt;/code&gt; is the request Attune would hand back on that container. &lt;code&gt;$13.58&lt;/code&gt; is &lt;code&gt;0.6&lt;/code&gt; cores times &lt;code&gt;$0.031&lt;/code&gt; times &lt;code&gt;730&lt;/code&gt; hours. With ten replicas that is 6 cores, about $136 a month. &lt;code&gt;savings&lt;/code&gt; still prints the one container, so multiply by your replica count.&lt;/p&gt;

&lt;p&gt;If you want that cut, change the type. If you don't, leave &lt;code&gt;Recommend&lt;/code&gt;. Nothing has been resized.&lt;/p&gt;

&lt;p&gt;To see that the policy is only looking:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;kubectl get attunepolicies &lt;span class="nt"&gt;-n&lt;/span&gt; production
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;NAME           TYPE        WORKLOADS   RECS   RESIZED   READY   AGE
api-services   Recommend   1           1      0         True    5m
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;RECS&lt;/code&gt; counts workloads with a recommendation. &lt;code&gt;RESIZED&lt;/code&gt; stays 0 while the type is &lt;code&gt;Recommend&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Cut one pod, or a slice
&lt;/h2&gt;

&lt;p&gt;When you leave &lt;code&gt;Recommend&lt;/code&gt;, Attune changes CPU and memory. CPU can go down. Memory can go up, and it does not go down unless you set &lt;code&gt;memory.allowDecrease: true&lt;/code&gt;. That default keeps a tight number from OOM-killing a JVM that sized its heap at startup.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;OneShot&lt;/code&gt; resizes one pod that still needs it, waits out a 1 hour cooldown, then resizes the next. Ten replicas of one Deployment take about ten hours. Switch the type back to &lt;code&gt;Recommend&lt;/code&gt; to stop. Pods already resized keep the new size.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Canary&lt;/code&gt; resizes a slice and then waits:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;updateStrategy&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Canary&lt;/span&gt;
  &lt;span class="na"&gt;canary&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;percentage&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="m"&gt;10&lt;/span&gt;
    &lt;span class="na"&gt;observationPeriod&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;5m&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The block needs both fields, or the API server rejects it. &lt;code&gt;autoPromote&lt;/code&gt; defaults to false, so the rest of the fleet stays put until you set that to true or change the type to &lt;code&gt;Auto&lt;/code&gt;, which resizes the rest.&lt;/p&gt;

&lt;h2&gt;
  
  
  When the new size is wrong
&lt;/h2&gt;

&lt;p&gt;If a resized container is OOMKilled within 5 minutes (&lt;code&gt;safetyObservationPeriod&lt;/code&gt;), Attune puts the old request back. With Prometheus, CPU throttling above half of the periods does the same. A peak next Monday does not trigger a revert. A smaller size fits on the node. A later increase, or that revert, might not. The default is to wait and retry. The pod is not evicted.&lt;/p&gt;

&lt;p&gt;There is one trap: an HPA that scales on CPU utilization. Utilization is usage divided by the request. Shrink the request and the same pod suddenly looks hotter. The HPA adds replicas and the savings walk out the door. Attune rewrites the HPA target only when the HPA carries &lt;code&gt;attune.io/auto-tune: "true"&lt;/code&gt;. Without that annotation, set &lt;code&gt;minAllowed&lt;/code&gt; high enough that the request can't fall further than you planned.&lt;/p&gt;

&lt;h2&gt;
  
  
  Make the next deploy keep it
&lt;/h2&gt;

&lt;p&gt;An in-place resize changes the running pod. It does not change the Deployment in Git, so Argo CD and Flux do not call it drift. The next rollout still starts from the Git request.&lt;/p&gt;

&lt;p&gt;If Git owns the Deployment, leave the policy on &lt;code&gt;Recommend&lt;/code&gt; and commit the number:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;updateStrategy&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Recommend&lt;/span&gt;
  &lt;span class="na"&gt;export&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;configMap&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;kubectl attune diff &lt;span class="nt"&gt;-n&lt;/span&gt; production &lt;span class="nt"&gt;-o&lt;/span&gt; yaml
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That patch is what you commit. It carries the new requests for each Deployment. The ConfigMap is there for tools that read the numbers. Attune can also open a drift-report pull request. The &lt;a href="https://attune-io.github.io/attune/guides/gitops-integration/" rel="noopener noreferrer"&gt;GitOps guide&lt;/a&gt; covers dry run, and what not to turn on while Git owns the Deployment.&lt;/p&gt;

&lt;h2&gt;
  
  
  Other guides
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;A cluster autoscaler can drop a node once the requests are smaller. Attune does not do that drop. &lt;a href="https://attune-io.github.io/attune/guides/bin-packing/" rel="noopener noreferrer"&gt;Bin packing&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;The process only needs a big CPU while it starts. A &lt;a href="https://attune-io.github.io/attune/guides/startup-boost/" rel="noopener noreferrer"&gt;startup boost&lt;/a&gt; raises CPU for that window and then drops it. If &lt;code&gt;maxAllowed&lt;/code&gt; is already the steady request, the boost cannot rise.&lt;/li&gt;
&lt;li&gt;A resize during the lunch rush is a bad time. A schedule blocks the resize and still computes the number. &lt;a href="https://attune-io.github.io/attune/guides/auto-mode/" rel="noopener noreferrer"&gt;Auto mode&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;An error rate or a latency query matters more than an OOM. &lt;a href="https://attune-io.github.io/attune/guides/slo-guardrails/" rel="noopener noreferrer"&gt;SLO guardrails&lt;/a&gt; put the size back when that query breaches.&lt;/li&gt;
&lt;li&gt;The estimate can go to Slack or Teams once a week. &lt;a href="https://attune-io.github.io/attune/guides/weekly-report/" rel="noopener noreferrer"&gt;Weekly report&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;How are you setting CPU and memory today? If you try a Recommend policy, tell me in the comments how it goes.&lt;/p&gt;

</description>
      <category>kubernetes</category>
      <category>devops</category>
      <category>cloud</category>
      <category>opensource</category>
    </item>
  </channel>
</rss>
