Use KServe on ACK Knative to deploy AI models as serverless inference services. This approach provides key features such as auto-scaling, version management, and canary releases.
Step 1: Install and configure the KServe component
To ensure seamless integration with Knative's
ALB Ingress
or
Kourier gateway, install the KServe component and modify its settings to disable the creation of built-in Istio VirtualService resources.
-
Install the KServe component.
Log on to the ACK console. In the left navigation pane, click Clusters.
On the Clusters page, click the name of your cluster. In the left navigation pane, click .
-
On the Add-ons tab, find and deploy the KServe component in the Add-on Components section.
-
Disable Istio VirtualHost creation.
Edit the
inferenceservice-configConfigMap to setdisableIstioVirtualHosttotrue.kubectl get configmap inferenceservice-config -n kserve -o yaml \ | sed 's/"disableIstioVirtualHost": false/"disableIstioVirtualHost": true/g' \ | kubectl apply -f -Expected output:
configmap/inferenceservice-config configured -
Verify the configuration.
kubectl get configmap inferenceservice-config -n kserve -o yaml \ | grep '"disableIstioVirtualHost":' \ | tail -n1 \ | awk -F':' '{gsub(/[ ,]/,"",$2); print $2}'An output of
trueindicates that the configuration is updated. -
Restart the KServe controller to apply the configuration change.
kubectl rollout restart deployment kserve-controller-manager -n kserve
Step 2: Deploy the InferenceService
This example deploys a scikit-learn classification model trained on the Iris flower dataset. The model receives four flower measurements as input and predicts the corresponding species.
|
The input is an array of four ordered numerical features:
|
The output is the index of the predicted class:
|
-
Create an inferenceservice.yaml file to deploy the inference service.
apiVersion: "serving.kserve.io/v1beta1" kind: "InferenceService" metadata: name: "sklearn-iris" spec: predictor: model: # The format of the model. In this case, sklearn. modelFormat: name: sklearn image: "kube-ai-registry.cn-shanghai.cr.aliyuncs.com/ai-sample/kserve-sklearn-server:v0.12.0" command: - sh - -c - "python -m sklearnserver --model_name=sklearn-iris --model_dir=/models --http_port=8080" -
Deploy the InferenceService.
kubectl apply -f inferenceservice.yaml -
Check the service status.
kubectl get inferenceservices sklearn-irisA
READYstatus ofTrueindicates that the service is running properly.NAME URL READY PREV LATEST PREVROLLEDOUTREVISION LATESTREADYREVISION AGE sklearn-iris http://sklearn-iris-predictor-default.default.example.com True 100 sklearn-iris-predictor-default-00001 51s
Step 3: Access the service
Send an inference request to the service through the cluster's ingress gateway.
-
On the Knative page, on the Services tab, obtain the Gateway of the ALB Ingress or Kourier gateway and the Default Domain of the service.
This example uses an ALB Ingress. The UI for the Kourier gateway is similar.
In the service list, the status of sklearn-iris-predictor is Ready, and the default domain is
sklearn-iris-predictor.default.example.com. The gateway address of the ALB Ingress is displayed at the top of the page. Record the address and default domain. -
Prepare the request data.
In your local terminal, create a file named
./iris-input.jsonthat contains two arrays. Each array represents a sample for prediction.cat <<EOF > "./iris-input.json" { "instances": [ [6.8, 2.8, 4.8, 1.4], [6.0, 3.4, 4.5, 1.6] ] } EOF -
Send an inference request from your local terminal to access the service.
Replace
${INGRESS_DOMAIN}with the Gateway from step 1 of this section.curl -H "Content-Type: application/json" -H "Host: sklearn-iris-predictor.default.example.com" "http://${INGRESS_DOMAIN}/v1/models/sklearn-iris:predict" -d @./iris-input.jsonThe output indicates that the model predicts class index 1 for both input samples, which corresponds to Iris versicolour.
{"predictions":[1,1]}
Billing
The KServe and Knative components are free of charge. However, you are charged for the computing resources, such as ECS and ECI instances, and network resources, such as ALB and CLB instances, that you use. For more information, see Pricing of cloud resources.
FAQ
Why is my InferenceService stuck in the Not Ready state?
To troubleshoot this issue, perform the following steps:
-
Run the
kubectl describe inferenceservice <yourServiceName>command to check the events for any error messages. -
Run
kubectl get podsto check if any Pods related to the service (typically starting with the service name) are in anErrororCrashLoopBackOffstate. -
If a Pod is in an abnormal state, run the
kubectl logs <pod-name> -c kserve-containercommand to check the logs of the model serving container for model loading failures, such as being unable to download the model due to network issues or using an incorrect model file format.
How can I deploy my own trained model?
You can upload the model file to an OSS Bucket. When you create an InferenceService, set the spec.predictor.model.storageUri field to the URI of the model file. At the same time, correctly set the modelFormat field based on the model framework (for example, tensorflow, pytorch, or onnx).
How do I configure GPU resources for the model service?
If a model requires a GPU for inference, you can add the resources field to the predictor in the InferenceService YAML file to request GPU resources. The following is an example.
For more information about how to use GPU resources in Knative, see Use GPU resources.
spec:
predictor:
resources:
requests:
nvidia.com/gpu: "1"
limits:
nvidia.com/gpu: "1"
Related topics
-
For suggestions on configuring an AI model inference service in Knative, see Best practices for deploying AI model inference services in Knative.
-
ACK Knative includes an application template for Stable Diffusion. For more information, see Deploy a production-ready Stable Diffusion service with Knative.