如何设置熔断规则

    安装完成后,可以看到集群中增加了下面两个 NS,这两个 NS 中分别安装了基于 MetaProtocol 实现的 Dubbo 和 Thrift 协议的示例程序。 你可以选用任何一个程序进行测试。

    1. apiVersion: apps/v1
    2. kind: Deployment
    3. metadata:
    4. name: thrift-sample-server-fake
    5. namespace: meta-thrift
    6. labels:
    7. app: thrift-sample-server
    8. spec:
    9. selector:
    10. matchLabels:
    11. app: thrift-sample-server
    12. replicas: 1
    13. metadata:
    14. annotations:
    15. sidecar.istio.io/proxyImage: aeraki/meta-protocol-proxy:1.0.1
    16. sidecar.istio.io/rewriteAppHTTPProbers: "false"
    17. labels:
    18. app: thrift-sample-server
    19. spec:
    20. containers:
    21. - name: thrift-sample-server
    22. image: nginx
    23. ports:
    24. - containerPort: 9090
    25. EOF

    现在 thrift-sample-server service 中有三个 endpoint,其中 thrift-sample-server-fake 这个 deployment 中没有 thrift sample server,因此其对应的 endpoint “172.19.0.102” 并不能处理客户端的请求。从客户端的日志中可以看到每三次请求中就有一次错误信息:

    1. kubectl apply -f- <<EOF
    2. apiVersion: networking.istio.io/v1beta1
    3. kind: DestinationRule
    4. namespace: meta-thrift
    5. spec:
    6. host: thrift-sample-server
    7. trafficPolicy:
    8. outlierDetection:
    9. baseEjectionTime: 15m
    10. consecutive5xxErrors: 5
    11. interval: 5m
    12. EOF

    此时查看客户端的输出,可以看到客户端在熔断规则指定的错误次数后,不再将请求发送到出错的 endpoint “172.19.0.102”。

    1. aerakictl_sidecar_stats client meta-thrift|grep -i outlier
    2. cluster.outbound|9090||thrift-sample-server.meta-thrift.svc.cluster.local.outlier_detection.ejections_active: 1
    3. cluster.outbound|9090||thrift-sample-server.meta-thrift.svc.cluster.local.outlier_detection.ejections_consecutive_5xx: 1
    4. cluster.outbound|9090||thrift-sample-server.meta-thrift.svc.cluster.local.outlier_detection.ejections_detected_consecutive_5xx: 1
    5. cluster.outbound|9090||thrift-sample-server.meta-thrift.svc.cluster.local.outlier_detection.ejections_enforced_consecutive_5xx: 1
    6. luster.outbound|9090||thrift-sample-server.meta-thrift.svc.cluster.local.outlier_detection.ejections_enforced_total: 1