13. Service Mesh 服务网格

Istio 与 Linkerd 服务网格解析:Sidecar 架构、mTLS 安全通信、流量管理与可观测性实践

Service Mesh 通过在应用旁注入 Sidecar 代理,接管所有网络通信,实现流量管理、安全通信和可观测性,无需修改业务代码。

1. 架构

App Pod:
  ┌─────────────┐
  │  Application │ 业务代码,只与 localhost 通信
  └──────┬──────┘
         │ localhost
  ┌──────┴──────┐
  │   Envoy     │ Sidecar 代理:路由/负载均衡/mTLS/遥测
  └──────┬──────┘
         │ 网络

2. Istio 核心组件

组件功能
istiod控制平面:Pilot(配置分发)、Citadel(证书)、Galley(配置验证)
Envoy数据平面:Sidecar 代理
Ingress Gateway入口网关
Egress Gateway出口网关

2.1 流量管理

apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
  name: reviews-route
spec:
  hosts:
  - reviews
  http:
  - match:
    - headers:
        end-user:
          exact: jason
    route:
    - destination:
        host: reviews
        subset: v2
  - route:
    - destination:
        host: reviews
        subset: v1
      weight: 75
    - destination:
        host: reviews
        subset: v2
      weight: 25

2.2 熔断配置

apiVersion: networking.istio.io/v1beta1
kind: DestinationRule
metadata:
  name: reviews-circuit-breaker
spec:
  host: reviews
  trafficPolicy:
    connectionPool:
      tcp:
        maxConnections: 100
      http:
        http1MaxPendingRequests: 50
        maxRequestsPerConnection: 10
    outlierDetection:
      consecutiveErrors: 5
      interval: 30s
      baseEjectionTime: 30s

2.3 mTLS 自动加密

apiVersion: security.istio.io/v1beta1
kind: PeerAuthentication
metadata:
  name: default
  namespace: istio-system
spec:
  mtls:
    mode: STRICT  # 强制 mTLS

3. 与 Spring Cloud 对比

维度Spring CloudIstio
语言绑定Java 为主语言无关
侵入性需引入 SDK零侵入
功能齐全(配置/注册/熔断)侧重网络层
部署应用内Sidecar 独立
性能损耗中(Sidecar)
复杂度

4. Sidecarless 趋势

  • Ambient Mesh (Istio):ztunnel 节点代理 + waypoint proxy,减少 Sidecar 资源消耗
  • Cilium Service Mesh:eBPF 在内核层处理,性能更高

总结

  • 已有 Spring Cloud 微服务:增量引入 Istio 补充 mTLS 和流量管理
  • 全新云原生项目:直接上 Service Mesh
  • 资源敏感场景:考虑 Ambient Mesh 或 Cilium

继续阅读

探索更多技术文章

浏览归档,发现更多关于系统设计、工具链和工程实践的内容。

全部文章 返回首页

「distributed-systems」更多文章

  1. 分布式高可用架构模式:多活、容灾、降级与 K8s 编排高可用
  2. 分布式链路追踪实战:OpenTelemetry、Jaeger 与 W3C Trace Context
  3. 分布式缓存深度策略:Redis Cluster、一致性哈希与多级缓存架构