Sub topic 2
How KServe is put together
This chapter describes the components KServe installs in a cluster, what each one does, and how a request travels from a client to a model. It assumes you know basic Kubernetes (pods, deployments, services, namespaces), can apply YAML with kubectl, and understand HTTP and JSON. The previous chapter explained why a plain Deployment is not enough for model serving. This chapter shows what KServe adds.
The big picture
KServe is a set of Kubernetes extensions. It adds custom resource definitions (CRDs) and a controller that watches them. You describe the model you want served in a custom resource called an InferenceService. The controller reads that resource and creates the ordinary Kubernetes objects needed to run it: pods, services, and routing and scaling configuration.
You never write those lower-level objects yourself. This is the main thing KServe adds over a hand-written Deployment: one declarative object that stands for "this model, served at this endpoint, scaled this way."
KServe has two layers:
- Control plane. The controller manager and the CRDs. It turns your declarations into running workloads.
- Data plane. The pods that load a model and answer inference requests, plus the networking in front of them.
The control plane is not on the request path. If the controller is down, services that already run keep answering requests. You only lose the ability to create or change services until it returns.
The control plane
The KServe controller manager
The controller manager runs as a pod, normally in the kserve namespace. It is a standard Kubernetes controller. It watches InferenceService objects, compares the desired state with the actual state, and creates or updates the child resources until the two match.
Depending on the deployment mode, those child resources are:
- Knative Services, in Serverless mode.
- Kubernetes Deployments, Services, and optionally HorizontalPodAutoscalers, in RawDeployment mode.
The next-but-one chapters cover the two modes in detail. For now, remember that the same InferenceService can be realized in either way.
Custom resources
KServe defines several CRDs. These are the ones you will meet in this tutorial:
| Resource | Scope | Purpose |
|---|---|---|
| `InferenceService` | Namespaced | Declares one model service: predictor, optional transformer, scaling, and rollout settings |
| `ServingRuntime` | Namespaced | Describes a model server container that can serve certain model formats, usable only in its own namespace |
| `ClusterServingRuntime` | Cluster | Same as `ServingRuntime`, but available in every namespace |
| `InferenceGraph` | Namespaced | Chains several models or steps into a pipeline |
A ServingRuntime is a template. It names a container image, its arguments, and the model formats it supports. When you create an InferenceService that says modelFormat: sklearn, the controller looks for a runtime that supports sklearn and builds the pod from that template. A later chapter covers runtimes in depth.
The admission webhook
KServe registers a webhook with the Kubernetes API server. When a pod is about to be created for an InferenceService, the webhook modifies it. Its most important job is injecting the storage initializer, described below. The webhook also validates InferenceService objects, so some mistakes are rejected at kubectl apply time and do not show up later as a failed pod.
The data plane
Components of an InferenceService
An InferenceService has up to three components. Each one becomes its own set of pods.
- Predictor. Required. It loads the model and runs inference.
- Transformer. Optional. It runs pre-processing before the predictor and post-processing after it.
- Explainer. Optional. It produces explanations of predictions. This tutorial does not cover explainers.
Because each component is a separate workload, each scales independently. A CPU-bound transformer can run more replicas than a GPU-bound predictor.
Inside a predictor pod
A predictor pod contains more than one container. Seeing them explains most of the behavior you will observe with kubectl describe pod.
- Storage initializer. An init container, injected by the webhook. It runs before anything else. It downloads the model files from the
storageUri(for example a bucket in Google Cloud Storage or S3) into a volume shared with the main container, then exits. - Model server container (
kserve-container). It starts after the initializer finishes. It loads the model from the shared volume and listens for HTTP requests, and for gRPC if the runtime supports it. - Queue-proxy sidecar. Present in Serverless mode only. It is part of Knative. It counts in-flight requests, which Knative's autoscaler uses to decide on replica counts, and it enforces concurrency limits.
- Optional agent sidecar. Added when features such as request logging or model pulling are enabled.
Because the model is downloaded by an init container, the model server does not need credentials or any knowledge of where the model is stored. It reads files from a local path. This also means a slow or failing download shows up as a pod stuck in Init, not as a crashing model server.
Dependencies KServe builds on
KServe does not implement networking and autoscaling itself. It relies on other projects, and which ones you need depends on the mode.
| Dependency | Needed for | What it provides |
|---|---|---|
| Kubernetes | Always | Scheduling, pods, services |
| cert-manager | Always | TLS certificates for the admission webhook |
| Knative Serving | Serverless mode | Request-based autoscaling, scale to zero, revisions, traffic splitting |
| Istio, Kourier, or another ingress | Serverless mode, and external access in general | Routing external traffic to the right service |
| Gateway API or an ingress controller | RawDeployment mode | Routing external traffic when Knative is not used |
If you only plan to use RawDeployment mode, you can skip Knative. You then lose scale to zero and Knative-based canary splitting, but you also remove a large dependency.
How a request flows
The following diagram shows a prediction request in Serverless mode.
Three details in this flow cause common confusion.
- Routing uses the Host header. The gateway chooses the destination service from the host name, not from the URL path alone. This is why the
curlexample in the next chapter sets-H "Host: ${SERVICE_HOSTNAME}"when calling the cluster ingress by IP address. - The model is not downloaded per request. Download and loading happen once per pod start. A request that arrives while no pod is running (after scale to zero) waits for a new pod to start, download, and load the model. This is the cold start.
- Transformers add a hop. If you configure a transformer, the request goes to the transformer first. It calls the predictor over the cluster network, then returns the post-processed result.
Seeing the pieces in a running cluster
After you create an InferenceService (the next chapter does this step by step), you can list the objects KServe created. This script is a read-only inspection that you can run against any namespace that has a service named sklearn-iris. Replace the name and namespace as needed.
NAMESPACE=default
NAME=sklearn-iris
# The KServe control plane
kubectl get pods -n kserve
# The custom resource you created
kubectl get inferenceservice "$NAME" -n "$NAMESPACE"
# Runtimes available to the cluster and to this namespace
kubectl get clusterservingruntimes
kubectl get servingruntimes -n "$NAMESPACE"
# Pods created for the predictor, and their containers
kubectl get pods -n "$NAMESPACE" -l serving.kserve.io/inferenceservice="$NAME"
kubectl get pods -n "$NAMESPACE" -l serving.kserve.io/inferenceservice="$NAME" \
-o jsonpath='{.items[0].spec.initContainers[*].name}{"\n"}{.items[0].spec.containers[*].name}{"\n"}'The last command prints the init container names on one line and the regular container names on the next. You should see storage-initializer on the first line and kserve-container on the second, plus queue-proxy in Serverless mode.
Names of CRDs, labels, and namespaces can vary a little between KServe versions and installation methods. If a command returns nothing, run kubectl get crd | grep serving.kserve.io to confirm what is installed.
Common errors and what they tell you
Knowing the architecture makes failures easier to place. Match the symptom to the component.
| Symptom | Likely component | What to check |
|---|---|---|
| `kubectl apply` is rejected with a webhook error | Admission webhook or cert-manager | Are the `kserve` controller pods running and are the certificates valid? |
| `InferenceService` never becomes ready, no pods appear | Controller manager | Controller logs, and `kubectl describe inferenceservice` for conditions |
| Pod stuck in `Init` | Storage initializer | `kubectl logs <pod> -c storage-initializer`. Usually a wrong `storageUri` or missing credentials |
| Pod runs but crashes or never becomes ready | Model server | `kubectl logs <pod> -c kserve-container`. Often a model file that does not match the runtime or format |
| Service ready but requests return 404 or connection errors | Ingress and routing | The `Host` header, ingress address and port, and the service URL in the resource status |
| First request after idle is slow | Scale to zero | Expected cold start. Set `minReplicas: 1` if latency matters |
Summary of responsibilities
- The controller manager turns an
InferenceServiceinto running Kubernetes objects. - Runtimes supply the model server container for a model format.
- The storage initializer copies the model to the pod before the server starts.
- The model server answers inference requests.
- Knative and the ingress provide request-based scaling and routing in Serverless mode.
Exercise
A new InferenceService stays not ready. kubectl get pods shows the predictor pod in the Init:0/1 state for several minutes. Which container do you inspect first, which component is responsible, and what are two likely causes?
Show answer
Inspect the storage-initializer init container with kubectl logs <pod> -c storage-initializer. The storage initializer downloads the model from storageUri before the model server starts, so the model server container has not run yet. Likely causes are a wrong or unreachable storageUri (bad bucket or path, no network access) and missing or incorrect credentials for the object store.
Exercise
A teammate says the KServe controller pod crashed overnight and asks whether prediction traffic to existing services was interrupted. What do you answer, and what can you not do until it recovers?
Show answer
Existing services keep answering requests, because the controller is part of the control plane and is not on the request path. The data plane (ingress, queue-proxy, model server pods) keeps running. Until the controller recovers, you cannot create or update InferenceService objects in a way that takes effect, and failed pods or changes to scaling settings in the resource are not reconciled.