深入理解Istio流量管理的熔断配置

本文涉及的产品
服务治理 MSE Sentinel/OpenSergo,Agent数量 不受限
可观测可视化 Grafana 版,10个用户账号 1个月
简介: 创建目标规则,访问 httpbin 服务时应用熔断配置在 fortio 服务中向 httpbin 服务的发出并发请求

环境准备

httpbin 服务

httpbin 是一个使用 Python + Flask 编写的 HTTP 请求响应服务。

该服务主要用于测试 HTTP 库,你可以向他发送请求,然后他会按照指定的规则将你的请求返回。

部署 httpbin 服务:

```shell script
kubectl apply -f samples/httpbin/httpbin.yaml


## fortio 服务

Fortio是一个微服务(http, grpc)负载测试库,命令行工具,高级回显服务器和web UI在go (golang)。Fortio允许指定一组每秒查询负载,并记录延迟直方图和其他有用的统计数据。

部署 `fortio` 服务:

```shell
kubectl apply -f samples/httpbin/sample-client/fortio-deploy.yaml

httpbin 服务作为接收请求的服务端, fortio 服务作为发送请求的客户端。

熔断配置

创建目标规则,访问httpbin 服务时应用熔断配置:

kubectl apply -f - <<EOF
apiVersion: networking.istio.io/v1alpha3
kind: DestinationRule
metadata:
  name: httpbin
spec:
  host: httpbin
  trafficPolicy:
    connectionPool:
      http:
        http1MaxPendingRequests: 1
        maxRequestsPerConnection: 1
EOF

fortio 服务中向 httpbin 服务的发出并发请求:

```shell script
export FORTIO_POD=$(kubectl get pod -l app=fortio -n istio-demo -o jsonpath={.items..metadata.name})
kubectl exec -it "$FORTIO_POD" -c fortio -- /usr/bin/fortio load -c 5 -qps 0 -n 5 -loglevel Warning http://httpbin:8000/get


返回结果如下:

```text
I0725 11:43:55.895950 4039039 request.go:621] Throttling request took 1.130727121s, request: GET:https://172.24.28.71:6443/apis/ceph.rook.io/v1?timeout=32s
03:43:58 I logger.go:127> Log level is now 3 Warning (was 2 Info)
Fortio 1.17.1 running at 0 queries per second, 104->104 procs, for 5 calls: http://httpbin:8000/get
Starting at max qps with 5 thread(s) [gomax 104] for exactly 5 calls (1 per thread + 0)
03:43:58 W http_client.go:806> [3] Non ok http code 503 (HTTP/1.1 503)
03:43:58 W http_client.go:806> [1] Non ok http code 503 (HTTP/1.1 503)
03:43:58 W http_client.go:806> [2] Non ok http code 503 (HTTP/1.1 503)
Ended after 5.398808ms : 5 calls. qps=926.13
Aggregated Function Time : count 5 avg 0.0035955544 +/- 0.001035 min 0.002619591 max 0.005337051 sum 0.017977772
# range, mid point, percentile, count
>= 0.00261959 <= 0.003 , 0.0028098 , 60.00, 3
> 0.004 <= 0.005 , 0.0045 , 80.00, 1
> 0.005 <= 0.00533705 , 0.00516853 , 100.00, 1
# target 50% 0.0029049
# target 75% 0.00475
# target 90% 0.00516853
# target 99% 0.0053202
# target 99.9% 0.00533537
Sockets used: 5 (for perfect keepalive, would be 5)
Jitter: false
Code 200 : 2 (40.0 %)
Code 503 : 3 (60.0 %)
Response Header Sizes : count 5 avg 92 +/- 112.7 min 0 max 230 sum 460
Response Body/Total Sizes : count 5 avg 419.8 +/- 177.3 min 275 max 637 sum 2099
All done 5 calls (plus 0 warmup) 3.596 ms avg, 926.1 qps

可以看到,在发送的5个请求中,有3个请求返回 503 。

查看Envoy日志

执行下面的命令,查看fortio 服务的Envoy日志:

kubectl logs -l app=fortio -c istio-proxy

可以看到fortio服务对httpbin服务的调用的日志:

{
   
     "authority": "httpbin:8000",
     "bytes_received": 0,
     "bytes_sent": 81,
     "connection_termination_details": null,
     "downstream_local_address": "172.24.146.239:8000",
     "downstream_remote_address": "172.24.158.166:55030",
     "duration": 1,
     "method": "GET",
     "path": "/get",
     "protocol": "HTTP/1.1",
     "request_id": "3aa81a10-cddf-9b3b-b704-c1099b05c6fb",
     "requested_server_name": null,
     "response_code": 503,
     "response_code_details": "via_upstream",
     "response_flags": "-",
     "route_name": "allow_any",
     "start_time": "2022-07-22T09:19:04.465Z",
     "upstream_cluster": "PassthroughCluster",
     "upstream_host": "172.24.146.239:8000",
     "upstream_local_address": "172.24.158.166:55042",
     "upstream_service_time": "1",
     "upstream_transport_failure_reason": null,
     "user_agent": "fortio.org/fortio-1.17.1",
     "x_forwarded_for": null
}

其中,response_flags-,没有任何异常。

执行下面的命令,查看httpbin 服务的Envoy日志:

kubectl logs -l app=httpbin -c istio-proxy

可以看到httpbin服务被fortio服务调用的Envoy日志:

{
   
     "authority": "httpbin:8000",
     "bytes_received": 0,
     "bytes_sent": 81,
     "connection_termination_details": null,
     "downstream_local_address": "172.24.158.96:80",
     "downstream_remote_address": "172.24.158.166:55042",
     "duration": 0,
     "method": "GET",
     "path": "/get",
     "protocol": "HTTP/1.1",
     "request_id": "3aa81a10-cddf-9b3b-b704-c1099b05c6fb",
     "requested_server_name": null,
     "response_code": 503,
     "response_code_details": "upstream_reset_before_response_started{overflow}",
     "response_flags": "UO",
     "route_name": "default",
     "start_time": "2022-07-22T09:19:04.466Z",
     "upstream_cluster": "inbound|80||",
     "upstream_host": null,
     "upstream_local_address": null,
     "upstream_service_time": null,
     "upstream_transport_failure_reason": null,
     "user_agent": "fortio.org/fortio-1.17.1",
     "x_forwarded_for": null
}

其中,response_flagsUO,表示因为熔断产生的上游(upstream)溢出。

深入分析

通过Envoy日志,我们可以做出一些分析和判断:

httpbin服务的请求正常的时候,调用过程如下图:

httpbin服务的熔断被触发的时候,调用过程如下图:

httpbin服务熔断被触发时,返回503状态码的是httpbin服务的Envoy。

清理

kubectl delete destinationrule httpbin
kubectl delete -f samples/httpbin/httpbin.yaml
kubectl delete -f samples/httpbin/sample-client/fortio-deploy.yaml

最后,感谢你这么帅,还给我点赞

封面

相关实践学习
日志服务之使用Nginx模式采集日志
本文介绍如何通过日志服务控制台创建Nginx模式的Logtail配置快速采集Nginx日志并进行多维度分析。
相关文章
|
2月前
|
存储 JSON 监控
Higress Controller**不是将配置信息推送到Istio的内存存储里面的**。
【2月更文挑战第30天】Higress Controller**不是将配置信息推送到Istio的内存存储里面的**。
15 1
|
8月前
|
Kubernetes 负载均衡 监控
Istio 出错重试 重定向 熔断
Istio 出错重试 重定向 熔断
|
9月前
|
JSON Rust 安全
Istio Ambient Mesh Ztunnel实现剖析(1)配置解析
前言在Istio Ambient Mesh中,社区引入了名为ztunnel的新组件,ztunnel的名字来源于Zero-Trust Tunnel,即零信任管道,Ztunnel 旨在专注于Ambient Mesh中工作负载4层安全能力,例如 mTLS、身份验证、L4 授权,而无需进行七层流量解析。ztunnel 确保流量高效、安全地传输到负责七层处理的Waypoint Proxy或在对端无waypo
200 0
|
7月前
|
Kubernetes 监控 Go
在Kubernetes上安装和配置Istio:逐步指南,展示如何在Kubernetes集群中安装和配置Istio服务网格
在Kubernetes上安装和配置Istio:逐步指南,展示如何在Kubernetes集群中安装和配置Istio服务网格
87 0
|
7月前
|
安全 前端开发 Cloud Native
Istio 探索:微服务的流量管理、安全性和策略加固
Istio 探索:微服务的流量管理、安全性和策略加固
41 0
|
12月前
|
Kubernetes Cloud Native Go
MoE 系列(三)|使用 Istio 动态更新 Go 扩展配置
上一篇我们用 Go 扩展实现了 Basic Auth,体验了 Go 扩展从 Envoy 接受配置。之所以这么设计,是想复用 Envoy 原有的 xDS 配置推送通道,今天我们就来体验一番,云原生的配置变更。
|
开发者 微服务
Istio 流量管理| 学习笔记
快速学习 Istio 流量管理
100 0
|
API 微服务 Perl
10个 Istio 流量管理 最常用的例子,你知道几个?
10 个 Istio 流量管理 最常用的例子,强烈建议收藏起来,以备不时之需。
356 0
10个 Istio 流量管理 最常用的例子,你知道几个?
|
微服务
自从用了 Kiali 以后才知道,配置 Istio 的 流量管理 是如此容易
在生产环境中,直接登录服务器是非常不方便的,我们可以使用Kiali配置Istio的流量管理。
317 0
自从用了 Kiali 以后才知道,配置 Istio 的 流量管理 是如此容易
|
Python
深入理解 Istio 流量管理的超时时间设置
HTTP 请求的超时可以用路由规则的 timeout 字段来指定,那么 Istio 到底是如何实现超时时间的呢?
638 0
深入理解 Istio 流量管理的超时时间设置