總目錄索引: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