7. 超时配置
超时配置用于设定请求转发的最大等待时间,若后端服务在超时时间内未返回响应,Sidecar代理会直接向客户端返回504超时错误,避免请求长时间阻塞占用资源,支持全局超时和单路径超时配置。

7.1 全局超时配置
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: demo-service-vs
namespace: default
spec:
hosts:
- demo-service
http:
- timeout: 3s # 全局超时(所有匹配路径均生效)
route:
- destination:
host: demo-service
subset: v17.2 单路径超时配置(覆盖全局)
http:
- match:
- uri:
prefix: /api/v1/slow
timeout: 10s # 单独为慢接口设置更长超时时间
route:
- destination:
host: demo-service
subset: v1
- timeout: 3s # 其他路径使用全局超时
route:
- destination:
host: demo-service
subset: v17.3 操作注意事项
超时时间需结合业务接口实际响应时间配置,过短易导致正常请求超时,过长会增加资源占用,建议通过Prometheus监控接口平均响应时间后合理设定。
Istio 1.20.8版本支持的最小超时时间为1ms,最大无限制,建议设置不超过30s,避免长时间阻塞。
作者:叶奕珺 创建时间:2026-01-23 14:47
最后编辑:叶奕珺 更新时间:2026-01-30 18:08
最后编辑:叶奕珺 更新时间:2026-01-30 18:08