DEBUG.WIKI
IPPeak:从目标地区访问网页,住宅代理、SEO 监测、广告验证
阿里云;从建站到云上业务;云服务器 · 数据库 · 对象存储;查看产品 →
搬瓦工;先看线路,再选 VPS;CN2 GIA · 对应线路套餐;查看线路 →

解决 Istio 报错 EgressGateway connection timeout 与 SNI 不匹配

分析 Istio 流量穿透 EgressGateway 报 connection timeout 及 SNI 握手失败根因,详解 ServiceEntry 与 Gateway 规则对齐步骤。

问题现象

在 Istio 服务网格中,将 Pod 访问外网的流量路由通过 EgressGateway 出口网关集中导出时,请求发生超时挂起:

curl: (28) Failed to connect to api.external.com port 443 after 15000 ms: Connection timed out

查看 istio-egressgateway 的 Envoy 日志:

[2026-11-15T10:05:00.123Z] "- - -" 0 - - - "-" 0 0 15001 - "-" "-" "-" "-" "198.51.100.20:443" egressgateway 10.244.1.10:44300 - -

请求在网关处未完成 TLS 握手即超时中断。

触发根因

  1. EgressGateway 的 Gateway 资源中 SNI 域名与实际请求不匹配:Gateway 配置的 hosts 或 sni 未包含目标外网域名。
  2. ServiceEntry 与 VirtualService 路由链断裂:Sidecar 将流量重写转发给 EgressGateway 时,丢失了原始的主机名头或未配置 PORT_AUTOPASSTHROUGH。
  3. 安全组阻断了 EgressGateway 节点的公网 443 出站流量。

诊断排查步骤

  1. 检查 Gateway 规则定义:
kubectl get gateway istio-egressgateway -n istio-system -o yaml
  1. 检查应用 Pod 发出的请求是否携带合法的 SNI:
openssl s_client -connect 127.0.0.1:443 -servername api.external.com

解决步骤与操作命令

步骤一:在 Gateway 中配置匹配的 SNI 转发规则

apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
  name: istio-egressgateway
  namespace: istio-system
spec:
  selector:
    istio: egressgateway
  servers:
  - port:
      number: 443
      name: tls
      protocol: TLS
    hosts:
    - api.external.com
    tls:
      mode: PASSTHROUGH

步骤二:完善 ServiceEntry 声明外部服务

apiVersion: networking.istio.io/v1alpha3
kind: ServiceEntry
metadata:
  name: external-api
  namespace: default
spec:
  hosts:
  - api.external.com
  ports:
  - number: 443
    name: tls
    protocol: TLS
  resolution: DNS
  location: MESH_EXTERNAL

步骤三:通过 DestinationRule 引导流量经过 EgressGateway

确保客户端到网关之间使用内部双向 TLS,网关到公网使用明文透传(PASSTHROUGH)。

验证方法

在业务 Pod 中发起 HTTPS 请求测试:

kubectl exec -it <app-pod> -- curl -I https://api.external.com

返回 HTTP 200 OK,EgressGateway 日志中正确记录转发字节与目标 IP,无任何超时记录。