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 Cloud | Istio |
|---|---|---|
| 语言绑定 | 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
继续阅读
探索更多技术文章
浏览归档,发现更多关于系统设计、工具链和工程实践的内容。