Sub topic 9
Canary rollouts and rollback
A new model version can pass offline evaluation and still behave badly in production. Live traffic differs from your test set, and the new version may be slower, use more memory, or fail on unusual inputs. A canary rollout limits the damage by sending a small share of requests to the new version while the old one keeps serving the rest. This chapter shows how to run that process with KServe, then promote or roll back the new version.
Prerequisites
This chapter assumes you have read the earlier chapters on the InferenceService resource, storageUri, and deployment modes. You should be comfortable with these points:
- You can write and apply an InferenceService manifest with
kubectl. - You know that KServe in Serverless mode uses Knative Serving to create revisions and route traffic.
- You can call a deployed endpoint with
curland aHostheader.
What a canary means in KServe
In KServe, a canary is a change to the predictor's spec, usually a new storageUri, combined with a traffic percentage for the new version. In Serverless mode, each change to the predictor spec makes Knative create a new immutable revision. A revision is a snapshot of the pod template, including the container image, arguments, and the model location that the storage initializer will download.
KServe tracks several revisions in the InferenceService status:
| Status field | Meaning |
|---|---|
| `latestCreatedRevision` | The newest revision Knative has created from your spec |
| `latestReadyRevision` | The newest revision whose pods are ready |
| `latestRolledoutRevision` | The newest revision that has received a full rollout (100% of traffic) |
| `previousRolledoutRevision` | The revision that was fully rolled out before the latest one |
When canaryTrafficPercent is set, KServe sends that percentage to the latest revision. The rest goes to the previous rolled-out revision. Both revisions stay running, so each can scale independently.
The mechanism depends on Knative traffic routing, so it works in Serverless mode. In RawDeployment mode there are no Knative revisions, and canaryTrafficPercent does not apply. If you need canaries in RawDeployment mode, you have to split traffic at another layer, such as your ingress, a Gateway API route, or a service mesh.
The rollout lifecycle
A canary has three possible outcomes: promote, hold, or roll back. The diagram shows the full flow.
Step 1: deploy the first version
The first revision has no previous revision to split against, so canaryTrafficPercent has no effect on it. Start with the plain service from the earlier chapters:
apiVersion: serving.kserve.io/v1beta1
kind: InferenceService
metadata:
name: sklearn-iris
spec:
predictor:
model:
modelFormat:
name: sklearn
storageUri: gs://kfserving-examples/models/sklearn/1.0/modelApply it and wait until it reports ready:
kubectl apply -f sklearn-iris.yaml
kubectl wait --for=condition=Ready inferenceservice/sklearn-iris --timeout=300sThis revision becomes both the latest and the previous rolled-out revision, and it receives 100% of traffic.
Step 2: start the canary
Now point the service at a new model location and set the canary percentage in the same manifest. The bucket path below is a placeholder for your own model:
apiVersion: serving.kserve.io/v1beta1
kind: InferenceService
metadata:
name: sklearn-iris
spec:
predictor:
canaryTrafficPercent: 10
model:
modelFormat:
name: sklearn
storageUri: gs://example-bucket/models/sklearn/iris/v2Apply it with kubectl apply -f. Knative creates a second revision, its pods download the new model, and traffic splits 90/10 once the new pods are ready. Until the new revision is ready, the old one keeps serving everything, so a broken model path does not cause an outage by itself.
Step 3: check the split
The kubectl get output includes the traffic share of the previous and latest revisions:
kubectl get inferenceservice sklearn-irisFor the exact revision names, read the status directly:
kubectl get inferenceservice sklearn-iris \
-o jsonpath='{.status.components.predictor.latestRolledoutRevision}{"\n"}{.status.components.predictor.latestCreatedRevision}{"\n"}'
kubectl get inferenceservice sklearn-iris \
-o jsonpath='{.status.components.predictor.traffic}'The traffic list contains one entry per revision, with its percent and a tag such as prev or latest. If the two revision names match, no canary is in progress.
Testing a revision directly with tag routing
Random 10% sampling is a poor way to check one specific input. KServe can expose each tagged revision at its own URL. Enable tag routing with an annotation on the InferenceService:
apiVersion: serving.kserve.io/v1beta1
kind: InferenceService
metadata:
name: sklearn-iris
annotations:
serving.kserve.io/enable-tag-routing: "true"
spec:
predictor:
canaryTrafficPercent: 10
model:
modelFormat:
name: sklearn
storageUri: gs://example-bucket/models/sklearn/iris/v2With the annotation, the tagged revisions get host names prefixed with latest- and prev-. You can send the same request to each one and compare the answers. The exact host name appears in the traffic entries of the status, in the url field. Use that value as the Host header with the same ingress address you used earlier.
Step 4: decide using signals
Hold the canary at a low percentage long enough to see real behavior. Compare the two revisions on these signals:
- Error rate: HTTP 5xx and 4xx responses per revision.
- Latency: p50 and p99 request duration. A new model can be correct and still too slow.
- Resource use: memory and CPU of the new pods. Larger models can be killed for exceeding memory limits.
- Prediction quality: if you have delayed labels or a shadow comparison, check accuracy and the distribution of predictions.
Knative and KServe export per-revision metrics, so you can filter dashboards by revision name. The monitoring chapter later in this tutorial covers that in detail. Raise the percentage in steps, for example 10, 25, 50, and wait at each step long enough to collect a meaningful sample.
You raise the percentage by patching the field:
kubectl patch inferenceservice sklearn-iris --type=merge \
-p '{"spec":{"predictor":{"canaryTrafficPercent":50}}}'A patch that changes only canaryTrafficPercent does not create a new revision. It changes only the routing.
Step 5a: promote
When you are satisfied, promote the new revision by removing the canary field, which returns the traffic to the default of 100% on the latest revision:
kubectl patch inferenceservice sklearn-iris --type=json \
-p '[{"op":"remove","path":"/spec/predictor/canaryTrafficPercent"}]'After promotion, the new revision becomes the latest rolled-out revision, and the old one is no longer in the traffic list. Its pods scale down and, in Serverless mode, can reach zero. Update your stored manifest in Git as well, so the next kubectl apply of the file does not undo the change.
Step 5b: roll back
If the canary misbehaves, set the percentage to 0:
kubectl patch inferenceservice sklearn-iris --type=merge \
-p '{"spec":{"predictor":{"canaryTrafficPercent":0}}}'All traffic returns to the previous rolled-out revision. This is a routing change only, so it takes effect as soon as Knative updates the route, with no model download and no pod start. The failed revision remains defined but receives nothing, which lets you inspect its logs afterward.
Common errors and edge cases
- The percentage does nothing on the first deploy. There is no previous revision. The field matters only from the second rollout onward.
- The canary never receives traffic. Check
latestReadyRevision. If the new pods are not ready (for example, the storage initializer cannot reach the bucket), Knative keeps all traffic on the old revision. Inspect the pod's init container logs. - Changing other predictor fields starts a new revision. Resource limits, environment variables, and container arguments all create revisions. Treat any spec change as a rollout, and set the canary percentage in the same apply.
- Two quick updates in a row. If you change the spec again during a canary, the new change becomes the latest revision. The "previous rolled-out" revision stays the last one that got a full rollout. Finish or roll back one canary before starting the next.
- Scale to zero hides cold starts. A canary at 1% on a revision with
minReplicas: 0may repeatedly scale up from zero. Cold start latency then looks like model latency. SetminReplicas: 1for the duration of the test. - GitOps drift. If a controller such as Argo CD or Flux syncs the manifest, a manual
kubectl patchcan be reverted. Make canary changes in the repository so the tool applies them.
Design choices
KServe's built-in canary is simple, with two revisions and one percentage. That suits most single-model rollouts. It does not do automatic analysis, so no controller watches the metrics and promotes or rolls back for you. If you need that, pair KServe with a progressive delivery tool that adjusts canaryTrafficPercent based on metric checks. Also note that the percentage splits requests at random and not by user, so one client can see responses from both versions in a row.
Exercise
You run kubectl apply with a new storageUri and canaryTrafficPercent: 20. Metrics show a higher error rate on the new revision. You patch canaryTrafficPercent to 0, and errors stop. Later a teammate re-applies the same manifest from Git, still containing the new storageUri but with the canaryTrafficPercent line deleted. What happens, and what should you have done instead?
Show answer
Removing the field promotes the latest revision, so the faulty new model gets 100% of traffic and errors return. The rollback only pinned traffic to the old revision. It did not change the spec. The fix is to set storageUri in the Git manifest back to the old model location (or to a corrected model) and apply it, so the declared spec matches what you want to serve.
Exercise
A canary set to 5% never shows any requests on the new revision, and kubectl get inferenceservice still shows 100% on the previous revision. Name two checks that find the cause.
Show answer
First, compare latestReadyRevision with latestCreatedRevision in the status. If they differ, the new revision's pods are not ready. Second, inspect the new pod's events and the storage initializer logs for errors such as an unreachable bucket, missing credentials, or a wrong model path. Also confirm the service is in Serverless mode, because canaryTrafficPercent does not apply to RawDeployment.