IT七剑客 IT七剑客
首页
wresource
郭霖
孤寒者
IT邦德
沉默王二
老麦
stackoverflow
GitHub (opens new window)
首页
wresource
郭霖
孤寒者
IT邦德
沉默王二
老麦
stackoverflow
GitHub (opens new window)
  • 从零开始写 k8s 发布工具(一)

  • 从零开始写 k8s 发布工具(二)

  • 从零开始写 k8s 发布工具(三)

  • 从零开始写 k8s 发布工具(四)

  • istio的环境准备

  • istioVirtualService

    • isti VirtualService 和 k8s Ingress
    • 使用 istio Gateway 允许外部访问
    • VirtualService 使用路径重写
    • 使用 DestinationRule Subset 进行路由分组(版本控制)
    • VirtualService 使用 header 重写路由
    • VirtualService 路由重定向
    • VirtualService 重试机制
      • http retry
      • 测试
      • 设置 timeout
    • VirtualService 混沌测试/错误注入
    • VirtualService 服务委托
    • VirtualService Header 操作
    • Gateway 支持 https 访问 - 标准模式
    • 使用 DestionationRule 流量控制策略 - 简单负载均衡
  • 老麦 Go
  • istioVirtualService
老麦
2023-02-01
目录

VirtualService 重试机制

# VirtualService 重试机制

在 Istio VirtualService 中, 有一个很关键的机制: 重试。

发起重试不需要业务本身实现, 而是 istio 通过 envoy 发起的。

其中有几个关键参数

  1. attempts: 重试次数(不含初始请求), 即最大请求次数为 n+1。

  2. perTryTimeout: 发起重试的间隔时间。

    • 必须大于 1ms。
    • 默认于 http route 中的 timeout 一致, 即无 timeout 时间
  3. retryOn: 执行重试的触发条件。

    • 条件值有 envoy 提供: https://www.envoyproxy.io/docs/envoy/latest/configuration/http/http_filters/router_filter#x-envoy-retry-on

# http retry

---
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: review-http-redirect
  namespace: myistio
spec:
  gateways:
    - istio-tangx-in
  hosts:
    - svc-review
    - istio.tangx.in
  http:
    - match:
        - uri:
            prefix: /
      route:
        - destination:
            host: svc-review
      retries:  # 重试
        attempts: 3 # 重试次数(不含本身一次), 共计 4 次。
        perTryTimeout: 2s # 间隔时间, 默认 25ms。必须大于 1ms
        retryOn: gateway-error,connect-failure,refused-stream # 触发条件
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23

# 测试

部署用例 11 进行测试。

ka -f istio-samples/11-http-retry
1

执行 curl 请求命令, 通过结果可以看到, 总共耗时 8 秒。

time curl http://istio.tangx.in/review/delay?delay=3

    upstream request timeout

    real    0m8.118s
    user    0m0.000s
    sys     0m0.010s
1
2
3
4
5
6
7

通过 review 的日志可以看到, 总共请求了 4次 (1+3), 每次间隔 2秒 。 刚好 8 秒超时

[GIN] 2021/11/15 - 15:56:08 | 200 |  3.000822016s |       10.42.0.1 | GET      "/review/delay?delay=3"
[GIN] 2021/11/15 - 15:56:10 | 200 |  3.000916703s |       10.42.0.1 | GET      "/review/delay?delay=3"
[GIN] 2021/11/15 - 15:56:12 | 200 |  3.000723194s |       10.42.0.1 | GET      "/review/delay?delay=3"
[GIN] 2021/11/15 - 15:56:14 | 200 |  3.000565097s |       10.42.0.1 | GET      "/review/delay?delay=3"
1
2
3
4

# 设置 timeout

如下, 增加 http route 的全局 timeout 参数。

# ... 略
      timeout: 5s # 总请求时间不会操作 timeout 时常

      retries:  # 重试
        attempts: 3 
        perTryTimeout: 2s 
        retryOn: gateway-error,connect-failure,refused-stream 
1
2
3
4
5
6
7

虽然按照 重试 逻辑依旧需要 4次 8秒。 但受限于 timeout 的阈值, 请求在 5秒 后超时退出。

time curl  http://istio.tangx.in/review/delay?delay=3

    upstream request timeout

    real    0m5.012s
    user    0m0.009s
    sys     0m0.000s
1
2
3
4
5
6
7
上次更新: 2023/04/05, 05:23:58
VirtualService 路由重定向
VirtualService 混沌测试/错误注入

← VirtualService 路由重定向 VirtualService 混沌测试/错误注入→

最近更新
01
How the creator of Angular is dehydrating the web (Ep 574)
06-07
02
For those who just don’t Git it (Ep 573)
06-07
03
Modern work requires attention. Constant alerts steal it
06-07
更多文章>
Theme by Vdoing | Copyright © 2022-2024 IT七剑客 | MIT License
  • 闽ICP备2021006579号-4
  • 闽公网安备 35012102500470号
    • 跟随系统
    • 浅色模式
    • 深色模式
    • 阅读模式