Istio Locality-prioritized 负载平衡不起作用

Istio Locality-prioritized load balancing not working

无法配置本地优先负载平衡。 有两个带有标签的节点:

  labels:
    kubernetes.io/hostname: test-hw1
    topology.kubernetes.io/region: us
    topology.kubernetes.io/zone: wdc04
  labels:
    kubernetes.io/hostname: test-hw2
    topology.kubernetes.io/region: eu
    topology.kubernetes.io/zone: fra02

服务:

apiVersion: v1
kind: Service
metadata:
  name: cara
  namespace: default
  labels:
    app: cara
spec:
  selector:
    app: cara
  ports:
    - name: http
      appProtocol: http
      targetPort: http
      port: 8000

  topologyKeys:
    - "kubernetes.io/hostname"
    - "topology.kubernetes.io/zone"
    - "topology.kubernetes.io/region"
    - "*"

目的地规则:

apiVersion: networking.istio.io/v1alpha3
kind: DestinationRule
metadata:
  name: cara
spec:
  host: cara.default.svc.cluster.local
  trafficPolicy:
    connectionPool:
      http:
        http1MaxPendingRequests: 1

    outlierDetection:
      consecutive5xxErrors: 2
      baseEjectionTime: 5s

如果请求到达 test-hw1 节点,它有时仍然会无缘无故地路由到 test-hw2 节点。

事实证明,问题出在接受外部流量的 NodePort 服务中。默认情况下,服务是跨 pods 的负载平衡流量,因此有时连接会被路由到其他区域 istio-ingressgateway pod。 只需将 externalTrafficPolicy: Local 添加到在 NodePort 上接受来自外部流量的服务即可解决此问题。