<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>Autoscaling on vishctl</title><link>https://vishctl.dev/tags/autoscaling/</link><description>Recent content in Autoscaling on vishctl</description><generator>Hugo</generator><language>en-us</language><lastBuildDate>Sat, 14 Nov 2026 09:00:00 +0800</lastBuildDate><atom:link href="https://vishctl.dev/tags/autoscaling/index.xml" rel="self" type="application/rss+xml"/><item><title>Autoscaling LLM Inference on Kubernetes: Why CPU Fails and Queue Depth Works</title><link>https://vishctl.dev/posts/autoscaling-llm-inference-kubernetes-keda/</link><pubDate>Sat, 14 Nov 2026 09:00:00 +0800</pubDate><guid>https://vishctl.dev/posts/autoscaling-llm-inference-kubernetes-keda/</guid><category>kubernetes</category><category>autoscaling</category><category>keda</category><category>vllm</category><category>inference</category><category>ai-infra</category><description>A simple, diagram-first guide to autoscaling vLLM on Kubernetes: why CPU and GPU utilization mislead the HPA, how to scale on queue depth with KEDA and Prometheus, and how to survive slow GPU cold starts.</description><content:encoded><![CDATA[<p>The default Kubernetes autoscaler watches CPU. That works for a web app, because a busy web app burns CPU.</p>
<p>A model server is different. The GPU does the work, so CPU stays calm while users wait in a queue. The autoscaler sees nothing wrong and does nothing.</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="cl">Web app autoscaling = scale when CPU is busy
</span></span><span class="line"><span class="cl">LLM autoscaling     = scale when requests are waiting
</span></span></code></pre></div><figure class="mermaid-figure">
  <div class="mermaid">flowchart TD
    subgraph CPU["Scaling on CPU"]
        direction LR
        A1["Traffic<br/>spike"] a1@--> A2["CPU at 12%<br/>target is 70%"]
        A2 a2@--> A3["No scale up"]
        A3 a3@--> A4["Queue grows<br/>users wait"]
    end

    subgraph QUEUE["Scaling on queue depth"]
        direction LR
        B1["Traffic<br/>spike"] b1@--> B2["20 requests<br/>waiting"]
        B2 b2@--> B3["Scale from<br/>1 to 4 replicas"]
        B3 b3@--> B4["Queue drains"]
    end

    CPU ~~~ QUEUE
    a1@{ animate: true }
    a2@{ animate: true }
    a3@{ animate: true }
    b1@{ animate: true }
    b2@{ animate: true }
    b3@{ animate: true }

    classDef input fill:#13264a,stroke:#38bdf8,color:#e6f6ff,stroke-width:2px;
    classDef idle fill:#101e27,stroke:#324950,color:#8aa0a8;
    classDef warn fill:#302410,stroke:#fbbf24,color:#fff3cf,stroke-width:2px;
    classDef router fill:#281d48,stroke:#a78bfa,color:#f1edff,stroke-width:2px;
    classDef gpu fill:#173f59,stroke:#22d3ee,color:#ecfeff,stroke-width:2px;
    class A1,B1 input;
    class A2,A3 idle;
    class A4 warn;
    class B2 router;
    class B3,B4 gpu;</div>
  <figcaption>Top: a CPU-based autoscaler misses the traffic spike. Bottom: a queue-based autoscaler sees waiting requests and adds replicas.</figcaption>
</figure>

<p>This post covers three things: which signal to scale on, how to wire it up with KEDA, and how to deal with the fact that a new GPU replica takes minutes to become useful.</p>
<p>It builds on the numbers from my <a href="https://vishctl.dev/posts/llm-inference-metrics-ttft-tpot-throughput-goodput/">inference metrics guide</a>. If TTFT and saturation point are unfamiliar, start there.</p>
<h2 id="how-the-hpa-decides">How the HPA decides</h2>
<p>The <strong>Horizontal Pod Autoscaler (HPA)</strong> runs one small formula over and over:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="cl">desired replicas = ceil( current replicas x current metric / target metric )
</span></span></code></pre></div><p>A quick example with CPU:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="cl">2 replicas, CPU at 90%, target 60%
</span></span><span class="line"><span class="cl">desired = ceil(2 x 90 / 60) = 3 replicas
</span></span></code></pre></div><p>The formula is fine. The whole question is <strong>which metric you feed it</strong>. Feed it a number that does not move with load, and it will never scale.</p>
<h2 id="why-the-usual-signals-fail">Why the usual signals fail</h2>
<h3 id="cpu-utilization">CPU utilization</h3>
<p>A vLLM Pod uses the CPU for tokenizing, scheduling, and streaming responses. The heavy math runs on the GPU.</p>
<p>So CPU usage tells you very little. A Pod serving 2 requests and a Pod drowning under 200 can report similar CPU numbers.</p>
<h3 id="gpu-utilization">GPU utilization</h3>
<p>This one looks like the obvious fix, and it is the most common mistake.</p>
<p>GPU utilization means &ldquo;the share of time the GPU was doing anything at all&rdquo;. With continuous batching, a GPU serving 4 requests and a GPU serving 40 can both read close to 100%.</p>
<div class="table-scroll">
  <table>
    <thead>
        <tr>
            <th scope="col">Concurrent requests</th>
            <th scope="col">GPU utilization</th>
            <th scope="col">Requests waiting</th>
            <th scope="col">Is the Pod healthy?</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>4</td>
            <td>95%</td>
            <td>0</td>
            <td>Yes, plenty of room</td>
        </tr>
        <tr>
            <td>32</td>
            <td>98%</td>
            <td>0</td>
            <td>Yes, at the sweet spot</td>
        </tr>
        <tr>
            <td>64</td>
            <td>99%</td>
            <td>25</td>
            <td>No, users are queueing</td>
        </tr>
    </tbody>
  </table>
</div>
<p>The middle column barely changes. The third column tells the whole story.</p>
<h3 id="what-works-instead">What works instead</h3>
<p>Good autoscaling signals for an LLM server share one property: <strong>they rise when users start waiting.</strong></p>
<div class="table-scroll">
  <table>
    <thead>
        <tr>
            <th scope="col">Signal</th>
            <th scope="col">vLLM metric</th>
            <th scope="col">Why it works</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>Queue depth</td>
            <td><code>vllm:num_requests_waiting</code></td>
            <td>Zero when healthy, climbs the moment capacity runs out</td>
        </tr>
        <tr>
            <td>Concurrency</td>
            <td><code>vllm:num_requests_running</code> plus waiting</td>
            <td>Lets you set a target load per replica</td>
        </tr>
        <tr>
            <td>KV cache pressure</td>
            <td><code>vllm:kv_cache_usage_perc</code></td>
            <td>Warns before long prompts start to be preempted</td>
        </tr>
        <tr>
            <td>Tail latency</td>
            <td>P95 of <code>vllm:time_to_first_token_seconds</code></td>
            <td>Matches what users feel, but reacts late</td>
        </tr>
    </tbody>
  </table>
</div>
<p><strong>Queue depth is the best first choice.</strong> It is simple, it is a leading indicator, and it means the same thing on every model and GPU.</p>
<h2 id="the-pieces-you-need">The pieces you need</h2>
<p>The built-in HPA cannot read a vLLM metric by itself. It needs a chain of helpers:</p>
<figure class="mermaid-figure">
  <div class="mermaid">flowchart LR
    V["vLLM Pods<br/>/metrics"] p1@--> P["Prometheus<br/>stores it"]
    P p2@--> K["KEDA<br/>queries it"]
    K p3@--> H["HPA<br/>does math"]
    H p4@--> D["Deployment<br/>resizes"]

    p1@{ animate: true }
    p2@{ animate: true }
    p3@{ animate: true }
    p4@{ animate: true }

    classDef gpu fill:#173f59,stroke:#22d3ee,color:#ecfeff,stroke-width:2px;
    classDef input fill:#13264a,stroke:#38bdf8,color:#e6f6ff,stroke-width:2px;
    classDef router fill:#281d48,stroke:#a78bfa,color:#f1edff,stroke-width:2px;
    class V,D gpu;
    class P input;
    class K,H router;</div>
  <figcaption>vLLM publishes the queue depth, Prometheus stores it, KEDA reads it and drives an HPA, and the HPA resizes the Deployment.</figcaption>
</figure>

<p><a href="https://keda.sh/">KEDA</a> (Kubernetes Event-Driven Autoscaling) is the glue. You describe a query and a threshold, and KEDA creates and manages the HPA for you.</p>
<h2 id="set-it-up">Set it up</h2>
<p>These steps assume a Deployment named <code>vllm</code> in a namespace named <code>llm</code>, with a container port named <code>http</code>, plus a running Prometheus. Adjust the names to match your cluster.</p>
<h3 id="1-make-sure-prometheus-scrapes-vllm">1. Make sure Prometheus scrapes vLLM</h3>
<p>If you run the Prometheus Operator, a <code>PodMonitor</code> does it:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-yaml" data-lang="yaml"><span class="line"><span class="cl"><span class="c"># vllm-podmonitor.yaml</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="nt">apiVersion</span><span class="p">:</span><span class="w"> </span><span class="l">monitoring.coreos.com/v1</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="nt">kind</span><span class="p">:</span><span class="w"> </span><span class="l">PodMonitor</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="nt">metadata</span><span class="p">:</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">  </span><span class="nt">name</span><span class="p">:</span><span class="w"> </span><span class="l">vllm</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">  </span><span class="nt">namespace</span><span class="p">:</span><span class="w"> </span><span class="l">llm</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="nt">spec</span><span class="p">:</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">  </span><span class="nt">selector</span><span class="p">:</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="nt">matchLabels</span><span class="p">:</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">      </span><span class="nt">app</span><span class="p">:</span><span class="w"> </span><span class="l">vllm</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">  </span><span class="nt">podMetricsEndpoints</span><span class="p">:</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span>- <span class="nt">port</span><span class="p">:</span><span class="w"> </span><span class="l">http</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">      </span><span class="nt">path</span><span class="p">:</span><span class="w"> </span><span class="l">/metrics</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">      </span><span class="nt">interval</span><span class="p">:</span><span class="w"> </span><span class="l">15s</span><span class="w">
</span></span></span></code></pre></div><div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">kubectl apply -f vllm-podmonitor.yaml
</span></span></code></pre></div><p>Confirm the metric exists before going further:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">kubectl -n llm port-forward deploy/vllm 8000:8000
</span></span></code></pre></div><div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">curl -s http://localhost:8000/metrics <span class="p">|</span> grep num_requests
</span></span></code></pre></div><h3 id="2-install-keda">2. Install KEDA</h3>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">helm repo add kedacore https://kedacore.github.io/charts
</span></span><span class="line"><span class="cl">helm repo update
</span></span></code></pre></div><div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">helm install keda kedacore/keda --namespace keda --create-namespace
</span></span></code></pre></div><h3 id="3-create-the-scaledobject">3. Create the ScaledObject</h3>
<p>This is the whole autoscaling policy in one file:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-yaml" data-lang="yaml"><span class="line"><span class="cl"><span class="c"># vllm-scaledobject.yaml</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="nt">apiVersion</span><span class="p">:</span><span class="w"> </span><span class="l">keda.sh/v1alpha1</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="nt">kind</span><span class="p">:</span><span class="w"> </span><span class="l">ScaledObject</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="nt">metadata</span><span class="p">:</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">  </span><span class="nt">name</span><span class="p">:</span><span class="w"> </span><span class="l">vllm-queue</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">  </span><span class="nt">namespace</span><span class="p">:</span><span class="w"> </span><span class="l">llm</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="nt">spec</span><span class="p">:</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">  </span><span class="nt">scaleTargetRef</span><span class="p">:</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="nt">name</span><span class="p">:</span><span class="w"> </span><span class="l">vllm</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">  </span><span class="nt">minReplicaCount</span><span class="p">:</span><span class="w"> </span><span class="m">1</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">  </span><span class="nt">maxReplicaCount</span><span class="p">:</span><span class="w"> </span><span class="m">4</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">  </span><span class="nt">pollingInterval</span><span class="p">:</span><span class="w"> </span><span class="m">15</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">  </span><span class="nt">triggers</span><span class="p">:</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span>- <span class="nt">type</span><span class="p">:</span><span class="w"> </span><span class="l">prometheus</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">      </span><span class="nt">metadata</span><span class="p">:</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">        </span><span class="nt">serverAddress</span><span class="p">:</span><span class="w"> </span><span class="l">http://prometheus-operated.monitoring.svc:9090</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">        </span><span class="nt">query</span><span class="p">:</span><span class="w"> </span><span class="l">sum(vllm:num_requests_waiting{namespace=&#34;llm&#34;})</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">        </span><span class="nt">threshold</span><span class="p">:</span><span class="w"> </span><span class="s2">&#34;5&#34;</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">  </span><span class="nt">advanced</span><span class="p">:</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="nt">horizontalPodAutoscalerConfig</span><span class="p">:</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">      </span><span class="nt">behavior</span><span class="p">:</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">        </span><span class="nt">scaleUp</span><span class="p">:</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">          </span><span class="nt">stabilizationWindowSeconds</span><span class="p">:</span><span class="w"> </span><span class="m">0</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">        </span><span class="nt">scaleDown</span><span class="p">:</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">          </span><span class="nt">stabilizationWindowSeconds</span><span class="p">:</span><span class="w"> </span><span class="m">600</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">          </span><span class="nt">policies</span><span class="p">:</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">            </span>- <span class="nt">type</span><span class="p">:</span><span class="w"> </span><span class="l">Pods</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">              </span><span class="nt">value</span><span class="p">:</span><span class="w"> </span><span class="m">1</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">              </span><span class="nt">periodSeconds</span><span class="p">:</span><span class="w"> </span><span class="m">300</span><span class="w">
</span></span></span></code></pre></div><div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">kubectl apply -f vllm-scaledobject.yaml
</span></span></code></pre></div><p>Change <code>serverAddress</code> to wherever your Prometheus lives. Then check that KEDA created the HPA:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">kubectl -n llm get scaledobject,hpa
</span></span></code></pre></div><h3 id="how-to-read-that-file">How to read that file</h3>
<p>The trigger says: <strong>keep about 5 waiting requests per replica, at most.</strong></p>
<p>The query sums the queue across all Pods. KEDA divides that total by the threshold:</p>
<div class="table-scroll">
  <table>
    <thead>
        <tr>
            <th scope="col">Step</th>
            <th scope="col">Total waiting</th>
            <th scope="col">Math</th>
            <th scope="col">Replicas</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>1</td>
            <td>0</td>
            <td>Nothing to do</td>
            <td>1 (the minimum)</td>
        </tr>
        <tr>
            <td>2</td>
            <td>8</td>
            <td>ceil(8 / 5)</td>
            <td>2</td>
        </tr>
        <tr>
            <td>3</td>
            <td>20</td>
            <td>ceil(20 / 5)</td>
            <td>4</td>
        </tr>
        <tr>
            <td>4</td>
            <td>60</td>
            <td>ceil(60 / 5) = 12, capped</td>
            <td>4 (the maximum)</td>
        </tr>
    </tbody>
  </table>
</div>
<p>Step 4 matters. Once you hit <code>maxReplicaCount</code>, the autoscaler is out of moves. That is the moment to shed load or return a &ldquo;busy&rdquo; response, not to let the queue grow forever.</p>
<p>I cover how in <a href="https://vishctl.dev/posts/llm-rate-limiting-load-shedding-tokens/">Rate Limiting LLM APIs</a>.</p>
<h3 id="an-alternative-target-concurrency-per-replica">An alternative: target concurrency per replica</h3>
<p>If you benchmarked your server and found its saturation point, you can scale on that directly.</p>
<p>Say one replica stays within its latency budget up to 32 concurrent requests. Then ask for one replica per 32 requests in the system:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-yaml" data-lang="yaml"><span class="line"><span class="cl"><span class="w">        </span><span class="nt">query</span><span class="p">:</span><span class="w"> </span><span class="l">sum(vllm:num_requests_running{namespace=&#34;llm&#34;}) + sum(vllm:num_requests_waiting{namespace=&#34;llm&#34;})</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">        </span><span class="nt">threshold</span><span class="p">:</span><span class="w"> </span><span class="s2">&#34;32&#34;</span><span class="w">
</span></span></span></code></pre></div><p>This version scales <strong>before</strong> a queue forms, which is gentler on users. It only works if you measured that 32 yourself. A number copied from someone else&rsquo;s GPU is a guess.</p>
<h2 id="the-hard-part-gpu-cold-starts">The hard part: GPU cold starts</h2>
<p>A new web Pod is ready in seconds. A new LLM Pod is not.</p>
<figure class="mermaid-figure">
  <div class="mermaid">flowchart LR
    S1["Scale up<br/>decided"] c1@--> S2["GPU node<br/>boots"]
    S2 c2@--> S3["Image<br/>pull"]
    S3 c3@--> S4["Weights<br/>load"]
    S4 c4@--> S5["Ready"]

    c1@{ animate: true }
    c2@{ animate: true }
    c3@{ animate: true }
    c4@{ animate: true }

    classDef router fill:#281d48,stroke:#a78bfa,color:#f1edff,stroke-width:2px;
    classDef warn fill:#302410,stroke:#fbbf24,color:#fff3cf,stroke-width:2px;
    classDef gpu fill:#173f59,stroke:#22d3ee,color:#ecfeff,stroke-width:3px;
    class S1 router;
    class S2,S3,S4 warn;
    class S5 gpu;</div>
  <figcaption>What a new replica goes through before it can answer: the node joins, a multi-GB image is pulled, and the weights load into GPU memory. Adding a GPU node is usually the longest step.</figcaption>
</figure>

<p>Each amber step can take minutes. Added together, a scale-up that the autoscaler decides at 12:00 may only help users at 12:08.</p>
<p>That changes how you tune everything. You are not reacting to load. You are <strong>predicting it a few minutes ahead</strong>.</p>
<h3 id="make-cold-starts-shorter">Make cold starts shorter</h3>
<div class="table-scroll">
  <table>
    <thead>
        <tr>
            <th scope="col">Slow step</th>
            <th scope="col">Fix</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>Node boot</td>
            <td>Keep one warm spare GPU node, or use low-priority placeholder Pods that hold a node until real work arrives</td>
        </tr>
        <tr>
            <td>Image pull</td>
            <td>Pre-pull the serving image on GPU nodes with a DaemonSet</td>
        </tr>
        <tr>
            <td>Weight download</td>
            <td>Store weights on a shared volume or node-local disk instead of downloading on every start</td>
        </tr>
        <tr>
            <td>Weight load</td>
            <td>Use a fast local disk for the model cache; network storage makes this step much slower</td>
        </tr>
    </tbody>
  </table>
</div>
<h3 id="tell-kubernetes-the-pod-is-slow-on-purpose">Tell Kubernetes the Pod is slow on purpose</h3>
<p>Without a startup probe, Kubernetes may kill a Pod that is still loading its model. Give it room:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-yaml" data-lang="yaml"><span class="line"><span class="cl"><span class="w">        </span><span class="nt">startupProbe</span><span class="p">:</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">          </span><span class="nt">httpGet</span><span class="p">:</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">            </span><span class="nt">path</span><span class="p">:</span><span class="w"> </span><span class="l">/health</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">            </span><span class="nt">port</span><span class="p">:</span><span class="w"> </span><span class="l">http</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">          </span><span class="nt">periodSeconds</span><span class="p">:</span><span class="w"> </span><span class="m">10</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">          </span><span class="nt">failureThreshold</span><span class="p">:</span><span class="w"> </span><span class="m">90</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">        </span><span class="nt">readinessProbe</span><span class="p">:</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">          </span><span class="nt">httpGet</span><span class="p">:</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">            </span><span class="nt">path</span><span class="p">:</span><span class="w"> </span><span class="l">/health</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">            </span><span class="nt">port</span><span class="p">:</span><span class="w"> </span><span class="l">http</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">          </span><span class="nt">periodSeconds</span><span class="p">:</span><span class="w"> </span><span class="m">5</span><span class="w">
</span></span></span></code></pre></div><p>That startup probe allows up to 15 minutes (90 checks, 10 seconds apart). The readiness probe keeps traffic away until the server can actually answer.</p>
<h3 id="scale-up-fast-scale-down-slow">Scale up fast, scale down slow</h3>
<p>Look back at the <code>behavior</code> block in the ScaledObject. It encodes one rule:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="cl">Scale up   = immediately, because a new replica is already minutes late
</span></span><span class="line"><span class="cl">Scale down = slowly, because removing a replica you need again costs minutes
</span></span></code></pre></div><p>The example waits 10 minutes of low load before scaling down, and then removes only one Pod every 5 minutes. A replica that sits idle for ten minutes costs far less than a second cold start during the next spike.</p>
<h2 id="should-you-scale-to-zero">Should you scale to zero?</h2>
<p>KEDA can set <code>minReplicaCount: 0</code>. Since Kubernetes v1.37 the built-in HPA can do it too, with <code>minReplicas: 0</code> on object or external metrics (see my <a href="https://vishctl.dev/posts/kubernetes-v1-37-stability/">v1.37 notes</a>). For an expensive GPU, that is tempting.</p>
<figure class="mermaid-figure">
  <div class="mermaid">flowchart TD
    subgraph ZERO["Minimum 0 replicas"]
        direction LR
        Z1["Idle<br/>GPU cost is zero"] z1@--> Z2["First request<br/>arrives"]
        Z2 z2@--> Z3["Cold start<br/>minutes of waiting"]
    end

    subgraph ONE["Minimum 1 replica"]
        direction LR
        O1["Idle<br/>one GPU paid for"] o1@--> O2["First request<br/>arrives"]
        O2 o2@--> O3["Answer starts<br/>right away"]
    end

    ZERO ~~~ ONE
    z1@{ animate: true }
    z2@{ animate: true }
    o1@{ animate: true }
    o2@{ animate: true }

    classDef idle fill:#101e27,stroke:#324950,color:#8aa0a8;
    classDef input fill:#13264a,stroke:#38bdf8,color:#e6f6ff,stroke-width:2px;
    classDef warn fill:#302410,stroke:#fbbf24,color:#fff3cf,stroke-width:2px;
    classDef gpu fill:#173f59,stroke:#22d3ee,color:#ecfeff,stroke-width:2px;
    class Z1,O1 idle;
    class Z2,O2 input;
    class Z3 warn;
    class O3 gpu;</div>
  <figcaption>Top: scale to zero saves money while idle, but the first user pays the full cold start. Bottom: one warm replica answers immediately.</figcaption>
</figure>

<p>There is also a chicken-and-egg problem. With zero Pods, nothing publishes <code>vllm:num_requests_waiting</code>, so a trigger based on it can never wake the Deployment up.</p>
<p>To scale from zero you need a signal from <strong>in front of</strong> the model server, such as request counts from your gateway or router. Something also has to hold the first request while the Pod starts.</p>
<div class="table-scroll">
  <table>
    <thead>
        <tr>
            <th scope="col">Workload</th>
            <th scope="col">Sensible minimum</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>Interactive chat or agents</td>
            <td>1 or more. Users will not wait minutes</td>
        </tr>
        <tr>
            <td>Internal tool used in office hours</td>
            <td>1 by day, 0 at night with a scheduled trigger</td>
        </tr>
        <tr>
            <td>Batch jobs with no deadline</td>
            <td>0. Nobody is watching the clock</td>
        </tr>
        <tr>
            <td>Many rarely used models</td>
            <td>0, behind a gateway that can queue the first request</td>
        </tr>
    </tbody>
  </table>
</div>
<h2 id="scale-down-without-dropping-answers">Scale down without dropping answers</h2>
<p>A streaming response can run for a minute or more. If Kubernetes removes a Pod mid-stream, that user gets half an answer.</p>
<p>Two settings help:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-yaml" data-lang="yaml"><span class="line"><span class="cl"><span class="w">    </span><span class="nt">spec</span><span class="p">:</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">      </span><span class="nt">terminationGracePeriodSeconds</span><span class="p">:</span><span class="w"> </span><span class="m">180</span><span class="w">
</span></span></span></code></pre></div><ul>
<li><strong>A generous grace period</strong> gives in-flight requests time to finish after the Pod is told to stop.</li>
<li><strong>A slow scale-down policy</strong> (already in the ScaledObject) means it happens rarely.</li>
</ul>
<p>Test this rather than trusting it. Start a long generation, delete the Pod, and watch whether the stream completes.</p>
<h2 id="common-mistakes">Common mistakes</h2>
<div class="table-scroll">
  <table>
    <thead>
        <tr>
            <th scope="col">Mistake</th>
            <th scope="col">What happens</th>
            <th scope="col">Do this instead</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>Scaling on GPU utilization</td>
            <td>Always near 100%, so it scales to max and stays there</td>
            <td>Scale on queue depth or concurrency</td>
        </tr>
        <tr>
            <td>Same speed up and down</td>
            <td>Replicas flap, and every flap is a cold start</td>
            <td>Fast up, slow down</td>
        </tr>
        <tr>
            <td>No startup probe</td>
            <td>Pods are killed while still loading weights</td>
            <td>Add a startup probe with a long budget</td>
        </tr>
        <tr>
            <td>Ignoring <code>maxReplicaCount</code></td>
            <td>Queue grows without limit once the cap is hit</td>
            <td>Alert at the cap and shed load</td>
        </tr>
        <tr>
            <td>Autoscaling without smart routing</td>
            <td>New replicas have cold KV caches, so TTFT gets worse first</td>
            <td>Pair it with <a href="https://vishctl.dev/posts/llm-d-kubernetes-inference-routing/">cache-aware routing</a></td>
        </tr>
        <tr>
            <td>Assuming a GPU will be there</td>
            <td>Pod stays <code>Pending</code> because no node has a free GPU</td>
            <td>Check node capacity and <a href="https://vishctl.dev/posts/kubernetes-gpu-sharing-time-slicing-mps-mig/">GPU sharing</a> limits first</td>
        </tr>
    </tbody>
  </table>
</div>
<h2 id="cheat-sheet">Cheat sheet</h2>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="cl">HPA                 = Kubernetes autoscaler: replicas x current metric / target metric
</span></span><span class="line"><span class="cl">Why CPU fails       = the GPU does the work, so CPU barely moves with load
</span></span><span class="line"><span class="cl">Why GPU util fails  = batching keeps it near 100% whether 4 or 40 requests are running
</span></span><span class="line"><span class="cl">Queue depth         = requests waiting for a slot; zero when healthy, the best first signal
</span></span><span class="line"><span class="cl">KEDA                = reads an external metric and drives an HPA for you
</span></span><span class="line"><span class="cl">ScaledObject        = the KEDA resource: target, min and max replicas, trigger, threshold
</span></span><span class="line"><span class="cl">threshold           = the metric value one replica should handle
</span></span><span class="line"><span class="cl">Cold start          = node boot + image pull + weight load, often several minutes
</span></span><span class="line"><span class="cl">startupProbe        = tells Kubernetes a Pod is allowed to be slow while it loads
</span></span><span class="line"><span class="cl">Stabilization window = how long the HPA waits before it trusts a lower number
</span></span><span class="line"><span class="cl">Scale to zero       = cheapest when idle, but the first request pays the whole cold start
</span></span><span class="line"><span class="cl">Rule of thumb       = scale up fast, scale down slow, and measure your own threshold
</span></span></code></pre></div><p>To find the threshold for your own model, use the load-curve method in the <a href="https://vishctl.dev/posts/llm-inference-metrics-ttft-tpot-throughput-goodput/">inference metrics guide</a>. To practice scaling Pods across fake GPUs with no hardware, try the <a href="https://vishctl.dev/posts/simulate-gpu-vllm-llm-d-on-laptop/">laptop GPU simulation lab</a>.</p>
]]></content:encoded></item></channel></rss>