Sub topic 3
Your First InferenceService
This chapter assumes that you understand Kubernetes pods, Deployments, Services, namespaces, and YAML manifests. You should also be able to use kubectl, read JSON, and call an HTTP endpoint with curl. The model in this example is already trained and stored in object storage.
Why use an InferenceService?
A Kubernetes Deployment can run a model server, but you must separately manage the server configuration, model loading, readiness, networking, and updates. KServe adds a Kubernetes resource called an InferenceService. It describes the model you want to serve and lets KServe create and manage the serving components.
An InferenceService usually specifies:
- The model format, such as scikit-learn, TensorFlow, PyTorch, or ONNX.
- The location of the model artifacts.
- Optional runtime, scaling, rollout, and processing settings.
- The name clients use when they send inference requests.
The KServe controller watches the resource and creates the required Kubernetes objects.
Create the service
The following manifest asks KServe to serve a scikit-learn model from Google Cloud Storage.
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/modelapiVersion identifies the KServe API version. kind says that this object is an InferenceService. The metadata.name value becomes part of the service identity and request path.
The predictor section describes the component that produces predictions. The modelFormat.name value tells KServe which model-serving behavior to use. storageUri points to the directory containing the saved model.
The Kubernetes cluster must be able to read this URI. For private storage, configure the appropriate cloud credentials through the cluster's supported secret or workload identity mechanism. Do not place access keys directly in the manifest.
Save the manifest as sklearn-iris.yaml, then apply it:
kubectl apply -f sklearn-iris.yaml
kubectl get inferenceservice sklearn-irisThe resource may take time to become ready. Inspect details and events when it is not ready:
kubectl describe inferenceservice sklearn-iris
kubectl get pods
kubectl get events --sort-by=.lastTimestampA serving pod must start, download the model, load it successfully, and pass its readiness checks. A temporary Unknown or False status during startup is normal. Persistent failure usually indicates an invalid storage URI, missing credentials, an unsupported model layout, or a runtime problem.
Send a prediction request
KServe supports standard inference protocols. A V1 request uses an instances field containing input rows:
cat <<'EOF' > iris-input.json
{"instances": [[6.8, 2.8, 4.8, 1.4], [6.0, 3.4, 4.5, 1.6]]}
EOF
curl -H "Host: ${SERVICE_HOSTNAME}" \
-H "Content-Type: application/json" \
"http://${INGRESS_HOST}:${INGRESS_PORT}/v1/models/sklearn-iris:predict" \
-d @./iris-input.jsonThe exact ingress host, port, and service hostname depend on your KServe installation. The response contains a predictions field with one result for each input row.
Check the deployment boundary
An InferenceService connects four boundaries:
| Boundary | What to verify |
|---|---|
| Kubernetes | The resource and serving pod are created |
| Storage | The model URI is reachable and readable |
| Runtime | The selected server understands the model format |
| HTTP | The request path and payload match the protocol |
Exercise
Which two manifest fields identify the model type and the location from which KServe loads it?
Show answer
spec.predictor.model.modelFormat.name identifies the model type, and spec.predictor.model.storageUri identifies the model location.