服务熔断

没有使用 熔断 的 DestinationRule

apiVersion: networking.istio.io/v1alpha3
kind: DestinationRule
metadata:
  name: nginx-desrule 
  namespace: version
spec: 
  host: nginx-service.version.svc.cluster.local
  subsets:
  - name: v1 
    labels: 
      version: v1
  - name: v2
    labels: 
      version: v2
  - name: v3
    labels: 
      version: v3

可以看到 无论是 1 连接并发,还是 10 连接并发 都没有错误返回 ( 非 200 )

服务熔断是一种保护措施,在服务实例无法正常提供服务的情况下,将其从负载均衡器中移除,不再分配任务

apiVersion: networking.istio.io/v1alpha3
kind: DestinationRule
metadata:
  name: nginx-desrule 
  namespace: version
spec: 
  host: nginx-service.version.svc.cluster.local
  trafficPolicy:
    connectionPool:
      tcp:
        maxConnections: 1
      http:
        http1MaxPendingRequests: 1
        maxRequestsPerConnection: 1
    outlierDetection:
      consecutiveErrors: 1
      interval: 1s
      baseEjectionTime: 3m
      maxEjectionPercent: 100
  subsets:
  - name: v1 
    labels: 
      version: v1
  - name: v2
    labels: 
      version: v2
  - name: v3
    labels: 
      version: v3
wrk -c 1 -t 1 http://hello.lizhe.com:31380/helloworld.html

加入了熔断之后,1 连接时候仍然是正常的,10连接并发的时候 75640 次请求中,出现了 71660 次错误

核心配置中

  trafficPolicy:
    connectionPool:
      tcp:
        maxConnections: 1
      http:
        http1MaxPendingRequests: 1
        maxRequestsPerConnection: 1
    outlierDetection:
      consecutiveErrors: 1
      interval: 1s
      baseEjectionTime: 3m
      maxEjectionPercent: 100

HTTP 和 TCP 连接池大小都是 1

maxConnections: 1
http1MaxPendingRequests: 1

每连接最大请求数

maxRequestsPerConnection: 1

只允许出错 1 次 (此方法已经过时)

consecutiveErrors: 1

没1秒做一次请求计数

interval: 1s

发生故障的的 pod 最少在被移除 3 分钟之后才能再次加入负载均衡池

baseEjectionTime: 3m

可以从负载均衡池中移除 100% 的 pod

maxEjectionPercent: 100

maxRequestsPerConnection 过时后 新的 配置

apiVersion: networking.istio.io/v1alpha3
kind: DestinationRule
metadata:
  name: nginx-desrule 
  namespace: version
spec: 
  host: nginx-service.version.svc.cluster.local
  trafficPolicy:
    connectionPool:
      tcp:
        maxConnections: 1
      http:
        http1MaxPendingRequests: 1
        maxRequestsPerConnection: 1
    outlierDetection:
      consecutive5xxErrors: 1
      consecutiveGatewayErrors: 1
      interval: 1s
      baseEjectionTime: 3m
      maxEjectionPercent: 100
  subsets:
  - name: v1 
    labels: 
      version: v1
  - name: v2
    labels: 
      version: v2
  - name: v3
    labels: 
      version: v3
outlier detection consecutive errors is deprecated, use consecutiveGatewayErrors or consecutive5xxErrors instead
destinationrule.networking.istio.io/nginx-desrule configured
Send a Message