Sub topic 3
Canary rollouts and rollback
This chapter assumes you can apply a Kubernetes manifest with kubectl, that you have a running KServe install, and that you have deployed an InferenceService before. It also covers custom predictors, transformers, InferenceGraph, and LLM serving at an introductory level.
Canary rollouts and rollback
A canary rollout sends a small share of traffic to a new model revision while the previous revision serves the rest. In KServe, you change storageUri and set canaryTrafficPercent:
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/v2To promote the new revision, remove canaryTrafficPercent so the latest revision receives all traffic. To roll back, set canaryTrafficPercent: 0, which routes all traffic to the previous revision.
Writing a custom predictor
When a built-in runtime cannot run your model, subclass Model from the KServe Python SDK. Load artifacts in load(), set self.ready, and implement predict():
from kserve import Model, ModelServer
class SumModel(Model):
def __init__(self, name: str):
super().__init__(name)
self.load()
def load(self):
self.ready = True
def predict(self, payload, headers=None):
instances = payload["instances"]
return {"predictions": [sum(row) for row in instances]}
if __name__ == "__main__":
ModelServer().start([SumModel("sum-model")])Package this file in a container image and reference that image from the InferenceService.
Adding pre- and post-processing with a transformer
A transformer is a separate container that runs before and after the predictor. It converts raw input into the model's expected format and reshapes the output. Add it under spec.transformer in the InferenceService.
Monitoring and troubleshooting a service
Start with the status conditions:
kubectl get inferenceservice sklearn-iris -o yaml
kubectl describe inferenceservice sklearn-iris
kubectl logs <predictor-pod> -c kserve-containerA Ready condition set to False usually points to a failed model download or a crashing container. Check the storage initializer logs when the model does not load.
Chaining models with InferenceGraph
An InferenceGraph is a separate resource that routes a request through several InferenceServices, for example a classifier followed by a specialized model. Each node names a service and the graph defines the routing between them.
Serving large language models and GPUs
LLMs need GPUs and large amounts of memory. Request GPUs in the predictor's resource limits, for example nvidia.com/gpu: 1, and choose a runtime built for LLM inference.
Exercise
A new revision is at canaryTrafficPercent 10, and error rates rise. What single change routes all traffic back to the stable revision?
Show answer
Set canaryTrafficPercent to 0 so the previous revision receives all requests.