Sub topic 7
Choosing a deployment mode
KServe can run an InferenceService in two ways: Serverless and RawDeployment. The mode decides which Kubernetes objects KServe creates, which add-ons your cluster needs, and how the service scales and rolls out. This chapter covers what each mode does, how to select one, and how to pick for a given workload.
This chapter assumes you have read the earlier chapters on the InferenceService resource and on KServe's components. You should also know how to read Deployments, Services, and HorizontalPodAutoscalers (HPAs) with kubectl.
What each mode creates
The InferenceService you write looks the same in both modes. The difference is what the KServe controller generates from it.
- Serverless hands the predictor to Knative Serving. The controller creates a Knative Service, and Knative creates revisions, routes, and the pods behind them. Each pod runs your model container plus a
queue-proxysidecar that Knative uses to count requests. Traffic enters through a Knative-compatible networking layer such as Istio or Kourier. - RawDeployment skips Knative. The controller creates a plain Kubernetes Deployment and Service for the predictor. It also creates an HPA when autoscaling is on. Ingress is handled by whatever the cluster provides, for example an Ingress or Gateway API route.
Selecting a mode
You can set the mode in two places.
- Cluster default. The
inferenceservice-configConfigMap in the KServe namespace has adeployentry with adefaultDeploymentModefield. The value isServerlessorRawDeployment. Installing KServe with the "standalone" or raw option usually sets this for you. - Per service. Add the annotation
serving.kserve.io/deploymentModeto the InferenceService. It overrides the cluster default for that one service.
apiVersion: serving.kserve.io/v1beta1
kind: InferenceService
metadata:
name: sklearn-iris
annotations:
serving.kserve.io/deploymentMode: RawDeployment
spec:
predictor:
model:
modelFormat:
name: sklearn
storageUri: gs://kfserving-examples/models/sklearn/1.0/modelThis is the same manifest as your first InferenceService with one added annotation. A per-service override only works if the cluster has what that mode needs. Requesting Serverless on a cluster with no Knative leaves the service unready.
To see which mode a service ended up in, inspect the objects it produced:
# The annotation, if one was set explicitly
kubectl get inferenceservice sklearn-iris \
-o jsonpath='{.metadata.annotations.serving\.kserve\.io/deploymentMode}{"\n"}'
# Serverless leaves a Knative Service and revisions
kubectl get ksvc,revision
# RawDeployment leaves a Deployment and an HPA
kubectl get deployment,hpaIf kubectl get ksvc returns a resource named after your service, the service runs in Serverless mode. If you find a Deployment whose name starts with sklearn-iris-predictor, it runs in RawDeployment mode. The exact suffix differs between KServe versions.
Comparing the two modes
| Concern | Serverless | RawDeployment |
|---|---|---|
| Extra dependencies | Knative Serving and a networking layer (Istio, Kourier, or similar) | None beyond Kubernetes and an ingress or Gateway API implementation |
| Scale to zero | Yes, with `minReplicas: 0` | Not by default |
| Default autoscaler | Knative Pod Autoscaler, driven by concurrency or requests per second | HPA, driven by CPU or memory |
| Canary traffic split | `canaryTrafficPercent` through Knative revisions | Not available through `canaryTrafficPercent` |
| Cold start | Present when scaled to zero | None while at least one replica runs |
| Per-pod overhead | `queue-proxy` sidecar | No extra sidecar |
| Pod spec freedom | Knative restricts some fields unless its feature flags are enabled | Any field Kubernetes accepts |
| Moving parts to operate | More | Fewer |
Check this table against the KServe version you run. Raw mode has gained features over time, such as KEDA-based autoscaling, and the details differ between releases.
Scaling behavior in each mode
Serverless scales on the load the queue-proxy observes. A setting such as scaleMetric: concurrency with scaleTarget: 10 means Knative aims for about ten in-flight requests per pod. This reacts quickly to bursts, and it is what allows an idle service to drop to zero pods.
RawDeployment uses the standard HPA. The HPA reads resource metrics from the metrics server, so you scale on CPU or memory utilization.
apiVersion: serving.kserve.io/v1beta1
kind: InferenceService
metadata:
name: sklearn-iris
annotations:
serving.kserve.io/deploymentMode: RawDeployment
spec:
predictor:
minReplicas: 2
maxReplicas: 6
scaleMetric: cpu
scaleTarget: 70
model:
modelFormat:
name: sklearn
storageUri: gs://kfserving-examples/models/sklearn/1.0/modelHere the HPA keeps CPU utilization near 70 percent across two to six replicas. The service never scales to zero, so the first request after a quiet period meets a running pod.
CPU is an indirect signal for inference. A model server that waits on a GPU may show low CPU while its request queue grows. If you need request-based scaling in raw mode, look at the KEDA integration that your KServe version offers. Do not assume scaleMetric: concurrency works there.
Rollouts in each mode
Serverless gets traffic splitting from Knative revisions. When you change storageUri and set canaryTrafficPercent: 10, Knative keeps the previous revision and sends it the remaining 90 percent. Rolling back means pointing traffic at the earlier revision again.
RawDeployment has no revision layer. A change to the spec becomes a normal rolling update of the Deployment, which replaces pods gradually but does not hold back a fixed share of traffic on the old model. If you need a percentage-based canary in raw mode, you must build it outside KServe, for example with weighted routes in your ingress or Gateway API. That is more work, and it is often the deciding factor for teams that release models frequently.
Decision criteria
Work through these questions in order.
In practice, these rules of thumb hold:
- Choose Serverless for many small or spiky models where idle cost matters, for services that use built-in canary releases, and for platforms where Knative is already part of the cluster.
- Choose RawDeployment for latency-sensitive services that cannot tolerate cold starts, for large models whose load time makes scale to zero impractical, for GPU workloads that need unrestricted pod specs, and for clusters where adding Knative and a service mesh is too much to operate.
- Mix modes when your workloads differ. The annotation is per service, so a cluster can serve a bursty tabular model in Serverless mode and a GPU-backed model in raw mode, provided both stacks are installed.
Common errors
- Service stays not ready after you set
Serverless. Knative is missing or its networking layer is not configured. Checkkubectl get ksvcand the KServe controller logs. canaryTrafficPercenthas no effect in raw mode. The field relies on Knative revisions. Use ingress-level weighting instead.minReplicas: 0leaves a pod running in raw mode. Without extra tooling, raw mode keeps at least one replica.- Changing the mode on an existing service. Switching modes replaces the underlying objects. Plan a short disruption, or deploy the service under a new name and move traffic over.
- Slow first request on a Serverless service. The pod was scaled to zero and must start, pull the image, and download the model. Set
minReplicas: 1for services that need steady latency.
Exercise
A team serves a 20 GB model on GPU nodes. The model takes several minutes to load, traffic is steady all day, and the cluster has no Knative installed. Which deployment mode fits, and which autoscaling signal should they be careful about?
Show answer
RawDeployment fits. There is no Knative, steady traffic gives scale to zero little value, and a slow model load would make cold starts painful. They should be careful with CPU-based HPA scaling, because a GPU-bound server can show low CPU while requests queue, so CPU may not reflect real load. A request-based signal such as KEDA, where the KServe version supports it, is a better fit.
Exercise
You set canaryTrafficPercent: 20 on a service annotated with serving.kserve.io/deploymentMode: RawDeployment and see no traffic split. Why, and what are two ways to fix it?
Show answer
The field depends on Knative revisions, which raw mode does not use, so the spec change becomes an ordinary rolling update. One fix is to move the service to Serverless mode, if Knative is available. The other is to split traffic outside KServe, for example with weighted routes in your ingress or Gateway API.