---

title: Istio 重试与超时策略端到端验证(Retry、Timeout 与故障注入)

date: 2025-11-26

keywords:

  • Retry
  • Timeout
  • Fault Injection
  • VirtualService
  • DestinationRule

description: 在VirtualService中配置重试与超时并通过故障注入进行端到端验证,提升鲁棒性同时避免对非幂等请求的副作用。

categories:

  • 文章资讯
  • 技术教程

---

概述

重试与超时在网络抖动与瞬时错误时提升成功率。通过故障注入验证策略效果,并在非幂等路径禁用或收紧重试以避免副作用。

关键实践与参数

  • 超时: 路由级别 timeout=5s
  • 重试: attempts=3 perTryTimeout=2s retryOn=5xx,connect-failure,gateway-error
  • 连接池: 设置请求与等待上限
  • 幂等控制: 对写操作关闭或限制重试

示例/配置/实现

apiVersion: networking.istio.io/v1beta1
kind: DestinationRule
metadata:
  name: api-dr
spec:
  host: api.svc.cluster.local
  trafficPolicy:
    connectionPool:
      http:
        http1MaxPendingRequests: 200
        maxRequestsPerConnection: 100
---
apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
  name: api-vs
spec:
  hosts: ["api.svc.cluster.local"]
  http:
    - match: [{ uri: { prefix: "/read" } }]
      timeout: 5s
      retries:
        attempts: 3
        perTryTimeout: 2s
        retryOn: "5xx,connect-failure,gateway-error"
      route:
        - destination: { host: api.svc.cluster.local, port: { number: 80 } }
    - match: [{ uri: { prefix: "/write" } }]
      route:
        - destination: { host: api.svc.cluster.local, port: { number: 80 } }
      retries:
        attempts: 0
---
apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
  name: api-fault
spec:
  hosts: ["api.svc.cluster.local"]
  http:
    - match: [{ uri: { prefix: "/read" } }]
      fault:
        delay:
          percentage: { value: 50 }
          fixedDelay: 2s
      route:
        - destination: { host: api.svc.cluster.local, port: { number: 80 } }

验证

  • 延迟场景: 在故障注入下读路径成功率提升且延迟受控
  • 非幂等保护: 写路径无重试避免重复写入
  • 资源影响: 请求与连接上限内无队列拥塞
  • 指标记录: 采集重试次数与超时比例

注意事项

  • 重试仅在幂等或安全路径启用
  • 超时需与上游与客户端协同
  • 故障注入在灰度环境执行
  • 设置告警监控重试激增

点赞(0) 打赏

评论列表 共有 0 条评论

暂无评论
立即
投稿

微信公众账号

微信扫一扫加关注

发表
评论
返回
顶部