部署KServe sklearn-iris模型时遇404及域名解析问题求助
Kubeflow KServe InferenceService调用问题排查与解决
问题场景
已在Kubeflow控制台Endpoints中注册sklearn-iris的InferenceService资源(禁用Istio Sidecar),控制台及kubectl查询均显示状态正常,但遇到以下问题:
- Python代码调用本地代理接口返回404
curl调用时出现域名解析失败- 已尝试修改KServe ingressgateway配置、验证集群DNS、确认网络连通性,问题仍未解决
环境版本:Ubuntu 20.04、Kubernetes 1.25.0、Kubeflow 1.7.0、KServe 0.9.0/0.10.0
排查与解决步骤
1. 验证本地代理端口转发配置
- 确认
kubectl port-forward命令是否指向正确的KServe ingressgateway服务:kubectl port-forward svc/kserve-ingressgateway 8080:80 -n istio-system - 检查本地端口是否被占用:
netstat -tulpn | grep 8080 - 确保调用URL路径与InferenceService名称匹配,本地代理的正确调用路径应为:
http://localhost:8080/v1/models/sklearn-iris:predict
2. 排查域名解析失败问题
- 获取InferenceService的实际访问域名:
kubectl get inferenceservices sklearn-iris -o jsonpath='{.status.url}' - 在集群内部测试域名解析(排除本地DNS问题):
kubectl run -it --rm --image=busybox:1.28 dns-test -- nslookup <获取到的InferenceService域名> - 若为测试环境自定义域名,需在本地
/etc/hosts中添加域名与集群Ingress网关IP的映射:<ingressgateway-external-ip> <inference-service-domain>
3. 禁用Istio Sidecar后的特殊配置检查
- 确认InferenceService的Sidecar禁用配置生效:
需确保kubectl get inferenceservices sklearn-iris -o yaml | grep -A 3 "sidecar"spec.predictor.sidecar.istio.enabled设为false - 检查Predictor服务是否正常暴露:
kubectl get svc -n <你的命名空间> | grep sklearn-iris - 直接转发Predictor服务端口测试连通性:
调用kubectl port-forward svc/sklearn-iris-predictor-default 9000:8080 -n <你的命名空间>http://localhost:9000/v1/models/sklearn-iris:predict验证服务是否正常响应
4. 验证KServe配置与版本兼容性
- 检查KServe全局配置,确认部署模式适配Sidecar禁用场景:
若使用Serverless模式,需确认Knative Serving是否正常运行;若为RawDeployment模式,需确保服务直接暴露kubectl get configmap inferenceservice-config -n kserve -o yaml | grep -A 5 "deploy" - 查看Predictor Pod日志,确认服务启动无异常:
重点检查端口监听、模型加载日志kubectl logs -n <你的命名空间> <sklearn-iris-predictor-pod-name> predictor
5. 验证请求格式正确性
- 确保请求体符合KServe要求的格式,示例:
{ "instances": [ [6.8, 2.8, 4.8, 1.4], [6.0, 3.4, 4.5, 1.6] ] } - Python代码中需设置正确的请求头:
import requests url = "http://localhost:8080/v1/models/sklearn-iris:predict" headers = {"Content-Type": "application/json"} data = {"instances": [[6.8, 2.8, 4.8, 1.4]]} response = requests.post(url, json=data, headers=headers) print(response.text)
内容的提问来源于stack exchange,提问作者TaeUk Noh
相关产品推荐
相关产品推荐

