Sub topic 8
Autoscaling and Scale to Zero
Assume you know Kubernetes pods, Deployments, Services, and YAML, and that you can apply manifests with kubectl. This chapter focuses on how KServe changes the number of model-serving replicas as request load changes.
The autoscaling model
A KServe InferenceService can set replica limits and a scaling target. The target describes how much work one replica should handle. With concurrency scaling, KServe measures the number of requests currently being processed. It adds replicas when that number stays above the target and removes replicas when demand falls.
For example, a target of 10 means the autoscaler aims for about ten in-flight requests per replica:
| Setting | Meaning |
|---|---|
| `minReplicas: 1` | Keep at least one replica running |
| `maxReplicas: 5` | Never run more than five replicas |
| `scaleMetric: concurrency` | Scale using in-flight requests |
| `scaleTarget: 10` | Aim for ten in-flight requests per replica |
The actual replica count can change gradually. Kubernetes and the serving platform use observation windows and stabilization rules, so a short burst does not always create a new pod immediately.
Configure concurrency-based scaling
This manifest keeps one warm replica, permits up to five replicas, and targets ten concurrent requests per replica:
apiVersion: serving.kserve.io/v1beta1
kind: InferenceService
metadata:
name: sklearn-iris
spec:
predictor:
minReplicas: 1
maxReplicas: 5
scaleMetric: concurrency
scaleTarget: 10
model:
modelFormat:
name: sklearn
storageUri: gs://kfserving-examples/models/sklearn/1.0/modelApply the resource and inspect its status:
kubectl apply -f sklearn-iris.yaml
kubectl get inferenceservice sklearn-iris
kubectl get pods -l serving.kserve.io/inferenceservice=sklearn-irisConcurrency is useful when each request consumes similar processing capacity. If request sizes vary greatly, concurrency alone may be a poor proxy for load. A large batch and a small request both count as one request. In that case, consider request-per-second scaling, CPU-based scaling where supported, or application-specific metrics.
Scale to zero
Scale to zero means that KServe removes all model replicas when there has been no traffic for a configured period. The next request starts a new pod and waits for the model to load. This reduces idle cost but introduces a cold start.
Scale to zero requires the Serverless deployment mode and its Knative-based request activation path. Set minReplicas to 0:
spec:
predictor:
minReplicas: 0
maxReplicas: 5
scaleMetric: concurrency
scaleTarget: 10The first request may wait for scheduling, image download, storage initialization, and model loading. Large models can make this delay substantial. Use minReplicas: 1 for latency-sensitive services that must respond quickly.
Choose the right setting
Use a nonzero minimum when traffic is steady or latency objectives are strict. Use zero when traffic is intermittent and clients can tolerate a cold start. Set the maximum from cluster capacity, model memory, and the maximum request load you want to accept.
Common errors include expecting minReplicas: 0 to work in every deployment mode, choosing a concurrency target without measuring request duration, and confusing pod readiness with model readiness. Check the InferenceService conditions and pod events when scaling does not behave as expected.
Exercise
Why might you choose minReplicas: 1 instead of minReplicas: 0 for a latency-sensitive prediction API?
Show answer
One replica remains warm, so requests avoid the scheduling and model-loading delay of a cold start.