Envoy 代理深度解析
Envoy 概述
Envoy 是 Istio 数据平面的核心组件,作为 Sidecar 注入到每个 Pod,拦截所有进出流量。
核心概念
Listener(监听器)
│ 接收连接
▼
Filter Chain(过滤器链)
├── Network Filter(L4)
│ └── HTTP Connection Manager(L7)
│ └── HTTP Filter(路由、限流、认证等)
▼
Cluster(上游集群)
│ 负载均衡
▼
Endpoint(具体实例)xDS API
Istio 通过 xDS API 动态配置 Envoy:
LDS(Listener Discovery Service) → 监听器配置
RDS(Route Discovery Service) → 路由配置
CDS(Cluster Discovery Service) → 集群配置
EDS(Endpoint Discovery Service) → 端点配置
SDS(Secret Discovery Service) → 证书配置查看 Envoy 配置
bash
# 查看 Envoy 配置(通过 istioctl)
istioctl proxy-config listener my-pod.production
istioctl proxy-config route my-pod.production
istioctl proxy-config cluster my-pod.production
istioctl proxy-config endpoint my-pod.production
# 查看完整配置
istioctl proxy-config all my-pod.production -o json
# 查看 Envoy 管理界面
kubectl port-forward my-pod 15000:15000
curl http://localhost:15000/config_dump
curl http://localhost:15000/stats/prometheusEnvoy 指标
# 请求统计
envoy_cluster_upstream_rq_total
envoy_cluster_upstream_rq_time
envoy_cluster_upstream_cx_active
# 熔断统计
envoy_cluster_upstream_rq_pending_overflow
envoy_cluster_upstream_rq_retry
# 连接统计
envoy_listener_downstream_cx_active
envoy_listener_downstream_cx_total调试
bash
# 查看访问日志
kubectl logs my-pod -c istio-proxy
# 修改日志级别
istioctl proxy-config log my-pod --level debug
# 检查 mTLS 状态
istioctl authn tls-check my-pod.production
# 分析配置问题
istioctl analyze -n production