总目录索引:istio从入门到放弃系列nginx
一、介绍后端
断路器是 Istio 提供的一个有用的技术。在微服务设置断路器能够有效保障微服务的抗操性。好比在断路器中,你能够设置服务并发链接次数限制或者服务调用失败次数,一旦达到设置的阈值,断路器将“跳闸”并中止与该主机的进一步链接。api
bash
二、Circuit breakers实例
并发
2.1 部署deploy资源
app
apiVersion: v1 kind: Service metadata: name: nginx-svc spec: selector: server: nginx ports: - name: http port: 80 targetPort: 80 protocol: TCP --- apiVersion: apps/v1 kind: Deployment metadata: name: nginx labels: server: nginx spec: replicas: 1 selector: matchLabels: server: nginx template: metadata: labels: server: nginx spec: containers: - name: nginx image: nginx:1.14-alpine imagePullPolicy: IfNotPresent
2.2 部署Dr资源ide
apiVersion: networking.istio.io/v1alpha3 kind: DestinationRule metadata: name: test-dr spec: host: nginx-svc trafficPolicy: connectionPool: http: http1MaxPendingRequests: 1 maxRequestsPerConnection: 1 outlierDetection: consecutiveErrors: 1 intercal: 10s baseEjectionTime: 10s masEjectionPercent: 100
详细说明以下:微服务
http1MaxPendingRequests: http 请求挂起状态的最大请求数
maxRequestsPerConnection: 必定时间内限制对后端服务发起的最大请求数,若是超过了此配置,就会出现限流。
outlierDetection.consecutiveErrors: 拒绝链接的最大失败次数
outlierDetection.interval: 触发熔断的时间间隔,在 interval 时间间隔内,达到 consecutiveErrors 即触发熔断
outlierDetection.baseEjectionTime: 熔断时长
maxEjectionPercent: 熔断链接最大百分比
ui
部署以上资源,并将deploy资源进行istio注入spa
istioctl kube-inject -f test-deploy.yaml |kubectl apply -f -
三、验证断路器
fortio load -c 10 -n 50 -qps 0 http://10.106.31.6