备考ICA----Istio实验9---熔断Circuit Breaking 实验

备考ICA----Istio实验9---熔断Circuit Breaking 实验

1. 环境准备

创建httpbin环境

bash 复制代码
kubectl apply -f istio/samples/httpbin/httpbin.yaml
kubectl get svc httpbin

2. 创建测试用客户端

bash 复制代码
kubectl apply -f istio/samples/httpbin/sample-client/fortio-deploy.yaml

3. 创建Httpbin的Circuit Breaking DR

参数 含义
maxConnections 到目标主机的HTTP1/TCP最大连接数量,只作用于http1.1,不作用于http2,因为后者只建立一次连接。
connectTimeout tcp连接超时时间,默认单位秒。也可以写其他单位,如ms。format: 1h/1m/1s/1ms. MUST BE >=1ms. Default is 10s.
tcpKeepalive 如果在套接字上设置SO_KEEPALIVE可以确保TCP 存活。
http1MaxPendingRequests http请求pending状态的最大请求数,从应用容器发来的HTTP请求的最大等待转发数,默认是 2^32-1。
maxRequestsPerConnection 在一定时间内限制对后端服务发起的最大请求数,如果超过了这个限制,就会开启限流。如果将这一参数设置为 1 则会禁止 keepalive 特性;
http2MaxRequests 后端请求的最大数量,默认是2^32-1。
idleTimeout 上游连接池连接的空闲超时。空闲超时被定义为没有活动请求的时间段。如果未设置,则没有空闲超时。当达到空闲超时时,连接将被关闭。注意,基于请求的超时意味着HTTP/2ping将无法保持有效连接。适用于HTTP1.1和HTTP2连接;
maxRetries 在给定时间内,集群中所有主机都可以执行的最大重试次数。默认为2^32-1。
h2UpgradePolicy 指定是否应将关联目标的 http1.1 连接升级到 http2。

circuit/httpbin-dr-Circuit.yaml

yaml 复制代码
kind: DestinationRule
metadata:
  name: httpbin
spec:
  host: httpbin
  trafficPolicy:
    connectionPool:
      tcp:
        maxConnections: 1
      http:
        http1MaxPendingRequests: 1
        maxRequestsPerConnection: 1
    outlierDetection:
      consecutive5xxErrors: 1
      interval: 1s
      baseEjectionTime: 3m
      maxEjectionPercent: 100

部署dr

bash 复制代码
kubectl apply -f circuit/httpbin-dr-Circuit.yaml

4. 访问测试

4.1 maxConnections=1

bash 复制代码
kubectl exec deploy/fortio-deploy -- /usr/bin/fortio curl -quiet http://httpbin:8000/get

当并发访问时会有一部分请求失败

bash 复制代码
kubectl exec deploy/fortio-deploy -- /usr/bin/fortio load -c 2 -qps 0 -n 20 -loglevel Warning http://httpbin:8000/get

因为2个并发,20次,不一定是50%的503.主要还是看同一时间内多少如果大于1个连接那么这个请求结束前其他请求就被拒绝.

放大请求数和并发数,被503熔断的请求比例会更多一点

bash 复制代码
kubectl exec deploy/fortio-deploy -- /usr/bin/fortio load -c 3 -qps 0 -n 30 -loglevel Warning http://httpbin:8000/get

可以查看 75 该 upstream_rq_pending_overflow 值,这意味着 75 到目前为止的调用已被标记为 Circuit

bash 复制代码
kubectl exec deploy/fortio-deploy -c istio-proxy -- pilot-agent request GET stats | grep httpbin | grep pending

2.2 调大maxConnections值

将maxConnections和http1MaxPendingRequests,maxRequestsPerConnection值一并调大后

circuit/httpbin-dr-Circuit.yaml

yaml 复制代码
apiVersion: networking.istio.io/v1alpha3
kind: DestinationRule
metadata:
  name: httpbin
spec:
  host: httpbin
  trafficPolicy:
    connectionPool:
      tcp:
        maxConnections: 2
      http:
        http1MaxPendingRequests: 2
        maxRequestsPerConnection: 2
    outlierDetection:
      consecutive5xxErrors: 1
      interval: 1s
      baseEjectionTime: 3m
      maxEjectionPercent: 100

部署dr

yaml 复制代码
kubectl apply -f  circuit/httpbin-dr-Circuit.yaml

再次用3并发测试30个连接

bash 复制代码
kubectl exec deploy/fortio-deploy -- /usr/bin/fortio load -c 3 -qps 0 -n 30 -loglevel Warning http://httpbin:8000/get

可见503的比例明显变小

即使将并发4请求40个连接也只有40%的被503

实际工作中我们可以根据请求量和服务性能来调整maxConnections,http1MaxPendingRequests,maxRequestsPerConnection的值通过熔断,牺牲掉一部分请求来保证其余请求的正常使用

5. 环境清理

bash 复制代码
kubectl delete -f istio/samples/httpbin/httpbin.yaml -f istio/samples/httpbin/sample-client/fortio-deploy.yaml
kubectl delete -f circuit/httpbin-dr-Circuit.yaml

至此Circuit Breaking 熔断实验完成

相关推荐
小猿姐12 小时前
MySQL Top 10 热点问题 AI 运维实战:从内核诊断到云原生运维
mysql·云原生·aiops
阿里云云原生2 天前
深入内核:拆解 OpenTelemetry eBPF 探针如何优雅地“透视”多语言微服务?
云原生
java_cj2 天前
深入kube-apiserver认证机制:从Bearer Token到mTLS的完整认证链解析
linux·运维·服务器·云原生·容器·kubernetes
互联网推荐官2 天前
上海软件定制开发公司推荐:从PaaS工程化路径看D-coding的技术取舍
云原生·云计算·paas·软件开发·开发经验·上海
sbjdhjd2 天前
从零搭建企业级 CI/CD(下):Jenkins+GitLab+Harbor 全链路实战指南
git·servlet·ci/cd·云原生·云计算·gitlab·jenkins
java_cj3 天前
深入kubectl create源码:从YAML到Pod的完整链路拆解
运维·云原生·容器·kubernetes
步步为营DotNet3 天前
基于.NET Aspire 实现云原生应用的高效监控与可观测性
云原生·.net·wpf
牛奶咖啡133 天前
KVM虚拟化与企业应用实践——给远端主机创建虚拟机
云原生·qemu·kvm·给远端主机创建虚拟机·创建uefi模式的虚拟机·安装openeulersp2·vnc与虚拟机环境搭建
java_cj3 天前
从kubectl学Visitor模式:如何优雅处理多态数据结构的遍历
云原生·golang·k8s·访问者模式
就改了3 天前
微服务异步场景链路断裂完整解决方案
微服务·云原生·架构