egressgateway:

apiVersion: networking.istio.io/v1beta1
kind: Gateway
metadata:
  name: egress
  namespace: istio-system
spec:
  selector:
    app: istio-egressgateway
  servers:
  - port:
      number: 80 # 出向流量端口
      name: http
      protocol: HTTP
    hosts:
    - "*"

vs:

apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
  name: nginx-external
spec:
  hosts:
  - nginx.ops.net
  gateways:
  - istio-system/egress
  - mesh # 网格内的每个sidecar envoy都会生成规则
  http:
  - match:
    - gateways:
      - mesh # 定义内部流量的走向
    route:
    - destination:
        host: istio-egressgateway.istio-system.svc.cluster.local # 也就是说 nginx.ops.net 的流量先发给egressgateway再由egressgateway来分发流量
  - match:
    - gateways:
      - istio-system/egress # 定义外部流量的走向
    route:
    - destination:
        host: nginx.ops.net
        subset: v21
      weight: 5
    - destination:
        host: nginx.ops.net
        subset: v20
      weight: 95

流量走向:这时候调用外部的流量都交由egressgateway来处理。

image.png