istio
Istio
一、介绍
Istio 是一个服务网格(Service Mesh),主要用于管理 Kubernetes 集群内部服务之间的通信。
核心能力:
- 流量管理:路由、灰度发布、金丝雀发布、故障注入。
- 安全管理:mTLS、身份认证、授权策略。
- 可观测性:Prometheus、Grafana、Jaeger、Kiali。
- 流量治理:限流、超时、重试、熔断。
- 网络控制:服务入口、出口流量、访问控制。
Istio 主要分为两个部分:
| 组件 | 作用 |
|---|---|
| istiod | 控制平面,管理配置、服务发现、证书和流量策略 |
| Envoy | 数据平面,代理服务之间的网络流量 |
| Ingress Gateway | 管理集群外部进入集群的流量 |
| Egress Gateway | 管理集群内部访问外部服务的流量 |
| Istio CNI | 可选组件,负责 Pod 网络流量重定向配置 |
控制平面与数据平面
Kubernetes Cluster
┌────────────────────────────────────────────────────┐
│ │
│ Control Plane │
│ ┌──────────────────────────────────────────────┐ │
│ │ istiod │ │
│ │ │ │
│ │ Pilot Certificate Authority │ │
│ │ xDS Security │ │
│ └──────────────────────┬───────────────────────┘ │
│ │ xDS │
│ ▼ │
│ Data Plane │
│ │
│ ┌────────────────┐ ┌────────────────┐ │
│ │ Namespace A │ │ Namespace B │ │
│ │ │ │ │ │
│ │ ┌────────────┐ │ │ ┌────────────┐ │ │
│ │ │ Service A │ │ │ │ Service B │ │ │
│ │ └─────┬──────┘ │ │ └─────┬──────┘ │ │
│ │ │ │ │ │ │ │
│ │ ┌──▼───┐ │ │ ┌──▼───┐ │ │
│ │ │Envoy │◄───┼───────┼───►│Envoy │ │ │
│ │ └──────┘ │ │ └──────┘ │ │
│ └────────────────┘ └────────────────┘ │
│ │
│ ┌──────────────────────────────────────────────┐ │
│ │ Gateway: Ingress / Egress │ │
│ └──────────────────────────────────────────────┘ │
└────────────────────────────────────────────────────┘
二、部署
部署方案选择
Istio 支持两种主要数据平面模式:
| 模式 | 说明 | 适用场景 |
|---|---|---|
| Sidecar | 每个业务 Pod 注入 Envoy | 通用生产环境 |
| Ambient | 使用节点级 ztunnel,按需使用 waypoint | 降低 Sidecar 资源开销 |
1、helm
helm repo add istio https://blob.istio.io/istio-release/charts
helm repo update
查看各个组件配置:
helm show values istio/base
helm show values istio/istiod
helm show values istio/gateway
helm show values istio/cni
helm show values istio/ztunnel
# istio-base
helm upgrade --install istio-base istio/base \
--namespace istio-system \
--wait
安装 istiod
istiod 是 Istio 的控制平面,负责:
- Kubernetes 服务发现。
- Envoy 配置下发(xDS)。
- Sidecar 注入。
- mTLS 证书签发和管理。
- 流量规则配置。
# istiod-values.yaml
pilot:
replicaCount: 1
resources:
requests:
cpu: 200m
memory: 512Mi
limits:
cpu: "2"
memory: 2Gi
meshConfig:
accessLogFile: /dev/stdout
accessLogEncoding: JSON
enableTracing: true
defaultConfig:
holdApplicationUntilProxyStarts: true
global:
logging:
level: "default:info"
helm upgrade --install istiod istio/istiod \
--namespace istio-system \
--version "$ISTIO_VERSION" \
-f istiod-values.yaml \
--wait
Ingress Gateway
Ingress Gateway 负责集群外部流量进入 Kubernetes 集群。
Internet
|
|
LoadBalancer
|
▼
Istio IngressGateway
|
Envoy
|
▼
VirtualService
|
▼
Kubernetes
|
▼
Service
|
▼
Application
# gateway-values.yaml
service:
type: LoadBalancer
replicaCount: 2
resources:
requests:
cpu: 100m
memory: 128Mi
limits:
cpu: "1"
memory: 512Mi
autoscaling:
enabled: true
minReplicas: 2
maxReplicas: 5
targetCPUUtilizationPercentage: 80
helm upgrade --install istio-ingressgateway istio/gateway \
--namespace istio-ingress \
--version "$ISTIO_VERSION" \
-f gateway-values.yaml \
--wait
Egress Gateway(可选)
Egress Gateway 用于统一管理集群访问外部网络的流量。
helm upgrade --install istio-egressgateway istio/gateway \
--namespace istio-egress \
--set service.type=ClusterIP \
--wait
后续通过 Gateway、ServiceEntry 和 VirtualService 配置出口流量。
Sidecar 自动注入
默认情况下,Kubernetes Pod 不会自动运行 Envoy,需要开启 Sidecar 注入
kubectl label namespace demo istio-injection=enabled
2、流量管理
Istio 流量管理的核心资源:
| 资源 | 功能 |
|---|---|
| Gateway | 管理入口/出口监听端口和协议 |
| VirtualService | 定义路由规则 |
| DestinationRule | 定义目标服务的子集和负载均衡策略 |
| ServiceEntry | 将集群外部服务注册到 Istio |
| Sidecar | 控制代理可见的服务范围 |
其中,VirtualService 负责决定请求发往哪里,DestinationRule 负责定义目标服务的策略
VirtualService 基本路由
apiVersion: networking.istio.io/v1
kind: VirtualService
metadata:
name: httpbin
namespace: demo
spec:
hosts:
- httpbin.demo.svc.cluster.local
http:
- route:
- destination:
host: httpbin.demo.svc.cluster.local
port:
number: 8000
金丝雀发布
# 假设有两个版本:
httpbin-v1
httpbin-v2
# Deployment 的标签:
labels:
app: httpbin
version: v1
# 第二个版本:
labels:
app: httpbin
version: v2
# 创建 httpbin-destination.yaml:
apiVersion: networking.istio.io/v1
kind: DestinationRule
metadata:
name: httpbin
namespace: demo
spec:
host: httpbin.demo.svc.cluster.local
subsets:
- name: v1
labels:
version: v1
- name: v2
labels:
version: v2
# 创建 httpbin-canary.yaml
apiVersion: networking.istio.io/v1
kind: VirtualService
metadata:
name: httpbin
namespace: demo
spec:
hosts:
- httpbin.demo.svc.cluster.local
http:
- route:
- destination:
host: httpbin.demo.svc.cluster.local
subset: v1
port:
number: 8000
weight: 90
- destination:
host: httpbin.demo.svc.cluster.local
subset: v2
port:
number: 8000
weight: 10
基于 Header 的灰度发布
例如只有请求头包含 x-canary: true 的请求才访问 v2:
```yaml` apiVersion: networking.istio.io/v1 kind: VirtualService metadata: name: httpbin namespace: demo spec: hosts: - httpbin.demo.svc.cluster.local http: - match: - headers: x-canary: exact: “true” route: - destination: host: httpbin.demo.svc.cluster.local subset: v2 port: number: 8000
- route:
- destination:
host: httpbin.demo.svc.cluster.local
subset: v1
port:
number: 8000
curl -H “x-canary: true” http://httpbin.demo.svc.cluster.local:8000/get
**超时控制**
```yaml
apiVersion: networking.istio.io/v1
kind: VirtualService
metadata:
name: httpbin
namespace: demo
spec:
hosts:
- httpbin.demo.svc.cluster.local
http:
- timeout: 3s
route:
- destination:
host: httpbin.demo.svc.cluster.local
port:
number: 8000
重试机制
apiVersion: networking.istio.io/v1
kind: VirtualService
metadata:
name: httpbin
namespace: demo
spec:
hosts:
- httpbin.demo.svc.cluster.local
http:
- retries:
attempts: 3
perTryTimeout: 2s
retryOn: connect-failure,reset,503
route:
- destination:
host: httpbin.demo.svc.cluster.local
port:
number: 8000
重试需要结合业务幂等性设计,避免对非幂等操作造成重复执行。
熔断与负载均衡
# 创建 httpbin-destination.yaml:
apiVersion: networking.istio.io/v1
kind: DestinationRule
metadata:
name: httpbin
namespace: demo
spec:
host: httpbin.demo.svc.cluster.local
trafficPolicy:
loadBalancer:
simple: LEAST_REQUEST
connectionPool:
tcp:
maxConnections: 100
http:
http1MaxPendingRequests: 100
http2MaxRequests: 100
outlierDetection:
consecutive5xxErrors: 5
interval: 10s
baseEjectionTime: 30s
maxEjectionPercent: 50
说明:
LEAST_REQUEST:优先选择当前请求较少的实例。maxConnections:限制连接池连接数。http1MaxPendingRequests:限制等待中的 HTTP/1 请求。outlierDetection:异常实例驱逐。
注意:熔断并不等于全局限流。需要全局限流时,应结合外部授权服务或专门的限流组件。
故障注入
用于测试微服务的容错能力:
apiVersion: networking.istio.io/v1
kind: VirtualService
metadata:
name: httpbin
namespace: demo
spec:
hosts:
- httpbin.demo.svc.cluster.local
http:
- fault:
delay:
percentage:
value: 50
fixedDelay: 5s
route:
- destination:
host: httpbin.demo.svc.cluster.local
port:
number: 8000
上述配置会让约 50% 的匹配请求延迟 5 秒。
仅建议在测试环境或明确限定范围的演练环境使用。
3、Istio Ingress Gateway 入口流量管理
Gateway 负责监听外部流量,例如 HTTP 80 和 HTTPS 443。
apiVersion: networking.istio.io/v1
kind: Gateway
metadata:
name: demo-gateway
namespace: demo
spec:
selector:
istio: ingressgateway
servers:
- port:
number: 80
name: http
protocol: HTTP
hosts:
- "httpbin.example.com"
4、Egress Gateway 出口流量控制
Istio 不仅可以控制外部访问集群,还可以控制集群内部访问外部服务。
Kubernetes Cluster
┌─────────────────────────────────────┐
│ │
│ ┌──────────────┐ │
│ │ Application │ │
│ └──────┬───────┘ │
│ │ │
│ ▼ │
│ ┌──────────────┐ │
│ │ Envoy Sidecar│ │
│ └──────┬───────┘ │
│ │ │
│ ▼ │
│ ┌──────────────┐ │
│ │ EgressGateway│ │
│ └──────┬───────┘ │
│ │ │
└─────────┼───────────────────────────┘
│
▼
External API
api.example.com
配置 ServiceEntry
例如允许访问外部 API:
# 例如允许访问外部 API:
apiVersion: networking.istio.io/v1
kind: ServiceEntry
metadata:
name: external-api
namespace: demo
spec:
hosts:
- api.example.com
location: MESH_EXTERNAL
ports:
- number: 443
name: https
protocol: HTTPS
resolution: DNS
限制外部服务访问
修改 Istio MeshConfig:
meshConfig:
outboundTrafficPolicy:
mode: REGISTRY_ONLY
helm upgrade istiod istio/istiod \
-n istio-system \
--version "$ISTIO_VERSION" \
-f istiod-values.yaml \
--set meshConfig.outboundTrafficPolicy.mode=REGISTRY_ONLY \
--wait
REGISTRY_ONLY 表示只允许代理识别和注册的外部目的地通过。
注意:
- DNS 解析不代表流量已被允许。
- 需要提前注册业务依赖的外部域名。
- 需要验证 DNS、TCP、TLS 和代理转发行为。
- 不要直接在生产集群启用后再逐步排查,否则可能导致第三方 API、镜像代理和外部数据库连接中断。
Egress Gateway 路由
先配置 Gateway:
apiVersion: networking.istio.io/v1
kind: Gateway
metadata:
name: external-gateway
namespace: istio-system
spec:
selector:
istio: egressgateway
servers:
- port:
number: 443
name: https
protocol: HTTPS
hosts:
- api.example.com
tls:
mode: PASSTHROUGH
再配置 VirtualService:
apiVersion: networking.istio.io/v1
kind: VirtualService
metadata:
name: external-api
namespace: demo
spec:
hosts:
- api.example.com
gateways:
- mesh
- istio-system/external-gateway
tls:
- match:
- gateways:
- mesh
port: 443
sniHosts:
- api.example.com
route:
- destination:
host: istio-egressgateway.istio-egress.svc.cluster.local
port:
number: 443
- match:
- gateways:
- istio-system/external-gateway
port: 443
sniHosts:
- api.example.com
route:
- destination:
host: api.example.com
port:
number: 443
这里使用 TLS Passthrough,出口 Gateway 根据 SNI 转发 TLS 流量,不解密 HTTPS。
生产使用时,还需要配合 DestinationRule 配置 Gateway 与外部服务之间的 TLS 连接,并根据 Gateway 实际 Service 端口及部署命名空间调整配置。
三、Istio 安全管理
Istio 的安全管理主要分为:
1)PeerAuthentication:服务之间的 mTLS。
2)RequestAuthentication:JWT 身份认证。
3)AuthorizationPolicy:访问授权。
4)DestinationRule:客户端 TLS 策略。
开启全局 mTLS
默认情况下,Istio 通常使用 PERMISSIVE 模式,允许明文和 mTLS 流量。
生产环境可以切换到 STRICT。
# mtls.yaml
apiVersion: security.istio.io/v1
kind: PeerAuthentication
metadata:
name: default
namespace: istio-system
spec:
mtls:
mode: STRICT
Service A Service B
┌──────────────┐ ┌──────────────┐
│ Application │ │ Application │
└──────┬───────┘ └──────┬───────┘
│ │
▼ ▼
┌──────────────┐ mTLS ┌──────────────┐
│ Envoy Proxy │◄──────────────►│ Envoy Proxy │
└──────────────┘ └──────────────┘
│ │
▼ ▼
Identity Identity
Istio 自动管理工作负载证书的签发和轮换。
AuthorizationPolicy 访问控制
例如只允许 frontend 服务访问 httpbin。
apiVersion: security.istio.io/v1
kind: AuthorizationPolicy
metadata:
name: httpbin-policy
namespace: demo
spec:
selector:
matchLabels:
app: httpbin
action: ALLOW
rules:
- from:
- source:
principals:
- cluster.local/ns/demo/sa/frontend
这里使用 ServiceAccount 身份,而不是 IP 地址进行授权。
创建 frontend ServiceAccount:
apiVersion: v1
kind: ServiceAccount
metadata:
name: frontend
namespace: demo
Frontend Deployment 中配置:
spec:
template:
spec:
serviceAccountName: frontend
注意:一旦某个工作负载存在 ALLOW 策略,未匹配规则的请求会被拒绝。需要提前规划其他调用方。
JWT 身份认证
创建 RequestAuthentication:
apiVersion: security.istio.io/v1
kind: RequestAuthentication
metadata:
name: jwt-auth
namespace: demo
spec:
selector:
matchLabels:
app: httpbin
jwtRules:
- issuer: https://auth.example.com
jwksUri: https://auth.example.com/.well-known/jwks.json
RequestAuthentication 主要负责验证 JWT 的有效性。
如果还需要强制请求必须携带 JWT,需要添加 AuthorizationPolicy:
apiVersion: security.istio.io/v1
kind: AuthorizationPolicy
metadata:
name: require-jwt
namespace: demo
spec:
selector:
matchLabels:
app: httpbin
action: ALLOW
rules:
- from:
- source:
requestPrincipals:
- "*"
Client
|
▼
Envoy
|
├── JWT 验证
|
├── 身份授权
|
▼
Application
Istio 可观测性-Kiali
Kiali 用于展示服务拓扑、请求流量和错误情况。
可以使用 Helm 部署 Kiali Server,但需要先配置 Kiali Operator 或其他受支持的安装方式。
frontend ──► user-service
│ │
│ ▼
└──────────► order-service
│
▼
postgres
Istio 与 Kubernetes NetworkPolicy / Cilium
这是生产部署时特别需要注意的部分。
Istio 和 Cilium 并不是相互替代的组件。
它们负责的网络层次不同:
| 功能 | Istio | Cilium |
|---|---|---|
| L3/L4 网络控制 | 部分支持 | 强项 |
| L7 HTTP 路由 | 强项 | 支持 |
| 服务间 mTLS | 支持 | 可通过其他机制实现 |
| 灰度发布 | 支持 | 不属于主要用途 |
| 流量重试 | 支持 | 不属于主要用途 |
| 服务身份认证 | 支持 | 支持基于身份的网络策略 |
| NetworkPolicy | 不替代 Kubernetes NetworkPolicy | 支持 |
| eBPF | 不依赖 eBPF | 核心技术 |
Internet
|
▼
Cilium / LB
|
▼
Istio Ingress Gateway
|
▼
VirtualService
|
▼
Cilium Network
|
┌────────────┴────────────┐
▼ ▼
Frontend Backend
│ │
Envoy Envoy
│ │
└────────── mTLS ─────────┘
|
▼
Database Service
建议职责:
- Cilium:负责 Pod 网络、IPAM、L3/L4 策略、NetworkPolicy。
- Istio:负责服务之间的 L7 流量管理、mTLS、服务身份和灰度发布。
- Ingress Gateway:负责 HTTP/HTTPS 入口流量。
- Egress Gateway:负责需要统一管控的出口流量。
四、Ambient
Ambient Mesh 是 Istio 提供的一种无 Sidecar 服务网格模式(Sidecar-less Service Mesh)。
它最大的变化是:不再要求每个业务 Pod 注入一个 Envoy Sidecar,而是将服务网格的数据平面能力下沉到 Kubernetes 节点级别,通过 ztunnel 和 Waypoint Proxy 实现流量转发、安全认证和 L7 流量治理。
1、Ambient Mesh 是什么?
传统 Istio Sidecar 模式:
Namespace: app
┌──────────────────────────────┐
│ Pod A │
│ ┌──────────┐ ┌────────────┐ │
│ │ App │ │ Envoy │ │
│ │ │ │ Sidecar │ │
│ └──────────┘ └────────────┘ │
└──────────────────────────────┘
┌──────────────────────────────┐
│ Pod B │
│ ┌──────────┐ ┌────────────┐ │
│ │ App │ │ Envoy │ │
│ │ │ │ Sidecar │ │
│ └──────────┘ └────────────┘ │
└──────────────────────────────┘
每个 Pod 都需要运行 Envoy。
Ambient 模式:
Namespace: app
┌──────────────────────────────┐
│ Pod A │
│ ┌──────────────────────────┐ │
│ │ App │ │
│ └──────────────────────────┘ │
└──────────────────────────────┘
┌──────────────────────────────┐
│ Pod B │
│ ┌──────────────────────────┐ │
│ │ App │ │
│ └──────────────────────────┘ │
└──────────────────────────────┘
│
▼
Node-level Proxy
ztunnel
│
▼
Waypoint Proxy
(按需部署)
Ambient 的核心设计:
- ztunnel:节点级 L4 代理,负责安全、身份认证和 TCP 转发。
- Waypoint:按需部署的 Envoy L7 代理,负责 HTTP、gRPC 路由和高级流量治理。
- Istiod:继续负责控制平面、配置下发和证书管理。
- Istio CNI:负责配置 Pod 流量重定向。
最重要的区别:Sidecar 是每个 Pod 一个代理;Ambient 是每个节点共享 ztunnel,需要 L7 能力时再部署 Waypoint。
2、ztunnel
ztunnel 全称 Zero Trust Tunnel,是 Ambient Mesh 的 L4 代理。
它使用 Rust 开发,不是 Envoy 的一个 Sidecar 变体。
主要职责:
| 功能 | 说明 |
|---|---|
| L4 代理 | TCP 流量转发 |
| mTLS | 服务之间双向 TLS 加密 |
| 身份认证 | 根据 Kubernetes ServiceAccount 识别工作负载 |
| 安全策略 | 执行 L4 级访问授权 |
| 流量重定向 | 接管需要进入 Mesh 的流量 |
| 连接管理 | 维护工作负载间的安全连接 |
ztunnel 采用 DaemonSet 部署。
Kubernetes Cluster
Node 1 Node 2
┌────────────────────┐ ┌────────────────────┐
│ │ │ │
│ ┌──────────────┐ │ │ ┌──────────────┐ │
│ │ App Pod A │ │ │ │ App Pod B │ │
│ └──────┬───────┘ │ │ └──────┬───────┘ │
│ │ │ │ │ │
│ ▼ │ │ ▼ │
│ ┌──────────────┐ │ │ ┌──────────────┐ │
│ │ ztunnel │◄─┼────────┼─►│ ztunnel │ │
│ └──────────────┘ │ mTLS │ └──────────────┘ │
│ │ │ │
└────────────────────┘ └────────────────────┘
注意:ztunnel 不是每个 Pod 单独运行,而是每个节点运行一个实例。它为节点上的工作负载提供数据平面代理能力。
3、Waypoint Proxy
Waypoint 是基于 Envoy 的 L7 代理。
ztunnel 负责 L4,Waypoint 负责更高级的 L7 功能。
| 功能 | ztunnel | Waypoint |
|---|---|---|
| TCP 转发 | 支持 | 支持 |
| mTLS | 支持 | 支持 |
| 工作负载身份 | 支持 | 支持 |
| L4 授权 | 支持 | 支持 |
| HTTP 路由 | 不负责 | 支持 |
| Header 匹配 | 不负责 | 支持 |
| HTTP 灰度发布 | 不负责 | 支持 |
| HTTP 超时 | 不负责 | 支持 |
| HTTP 重试 | 不负责 | 支持 |
| HTTP 故障注入 | 不负责 | 支持 |
Waypoint 可以按 Namespace 或 Service 等范围部署,不需要每个业务 Pod 一个代理。
Istiod
│
│ xDS
▼
┌──────────────┐
│ Waypoint │
│ Envoy Proxy │
└──────┬───────┘
│
┌─────────┴─────────┐
▼ ▼
Service A Service B
│ │
▼ ▼
App Pod App Pod
Ambient 模式需要通过网络重定向将 Pod 的流量交给 ztunnel。
Istio CNI 主要负责:
- 配置 Pod 网络重定向。
- 为 Ambient 工作负载设置流量拦截。
- 避免业务 Pod 依赖传统的
istio-initInit Container。 - 配合 ztunnel 实现数据平面流量接管。
因此,Ambient 并不是完全不需要网络代理,而是把代理从 Pod 内部移到了节点级别。
4、Ambient 流量转发原理
Ambient 的核心技术是 HBONE(HTTP-Based Overlay Network Environment)。
HBONE 是 Istio 用来在代理之间建立安全隧道的传输机制,通常基于 HTTP CONNECT 和 mTLS。
同节点通信
假设 Pod A 和 Pod B 位于同一个 Kubernetes Node:
Node 1
┌──────────────────────────────────────────┐
│ │
│ ┌─────────────┐ ┌─────────────┐ │
│ │ Pod A │ │ Pod B │ │
│ │ │ │ │ │
│ │ Application│ │ Application │ │
│ └──────┬──────┘ └──────▲──────┘ │
│ │ │ │
│ ▼ │ │
│ ┌───────────────────────────────────┐ │
│ │ ztunnel │ │
│ │ │ │
│ │ L4 Proxy + mTLS │ │
│ └───────────────────────────────────┘ │
│ │
└──────────────────────────────────────────┘
流量路径:
- Pod A 发起 TCP 请求。
- Istio CNI 将流量重定向到本节点 ztunnel。
- ztunnel 根据目标工作负载身份和服务信息确定转发路径。
- 通过安全传输连接目标工作负载。
- 目标端 ztunnel 将请求交给 Pod B。
跨节点通信
Kubernetes Cluster
Node 1 Node 2
┌──────────────────────┐ ┌──────────────────────┐
│ │ │ │
│ ┌──────────────┐ │ │ ┌──────────────┐ │
│ │ Pod A │ │ │ │ Pod B │ │
│ └──────┬───────┘ │ │ └──────▲───────┘ │
│ │ │ │ │ │
│ ▼ │ │ │ │
│ ┌──────────────┐ │ │ ┌──────┴───────┐ │
│ │ ztunnel │ │ │ │ ztunnel │ │
│ └──────┬───────┘ │ │ └──────▲───────┘ │
│ │ │ │ │ │
└─────────┼────────────┘ └─────────┼────────────┘
│ │
└──────────── HBONE / mTLS ──────────┘
跨节点时,两个 ztunnel 通过 HBONE 隧道传输流量。
默认使用端口:
15008/TCP
这个端口需要在节点网络和相关网络策略中允许必要的通信。
使用 Waypoint 的通信
当目标服务需要 HTTP 路由或 L7 授权时:
Pod A
│
▼
Source ztunnel
│
│ HBONE
▼
Waypoint Envoy
│
├── HTTP 路由
├── Header 匹配
├── JWT 验证
├── AuthorizationPolicy
├── 重试和超时
│
│ HBONE
▼
Destination ztunnel
│
▼
Pod B
Waypoint 主要负责目标工作负载的 L7 流量治理。它独立于业务 Pod 部署和扩缩容。
五、Ambient 与 Sidecar 对比**
这是选择 Istio 部署模式时最重要的参考。
| 对比项 | Sidecar | Ambient |
|---|---|---|
| 代理 | Envoy | ztunnel + 可选 Envoy |
| 部署方式 | 每个 Pod 注入 | 节点级 DaemonSet |
| L4 mTLS | 支持 | 支持 |
| L4 授权 | 支持 | 支持 |
| L7 流量治理 | Sidecar Envoy | Waypoint Envoy |
| 业务 Pod 重启 | 注入时需要 | 加入 Mesh 通常不需要 |
| 资源消耗 | 每个 Pod 都有代理 | L4 代理共享 |
| 代理升级 | 可能涉及业务 Pod 重建 | 可独立升级 |
| CNI 依赖 | 可选 Istio CNI | 必须使用 Istio CNI |
| 故障影响范围 | 单 Pod Sidecar | 节点 ztunnel 或共享 Waypoint |
资源消耗区别
假设:
- Kubernetes 有 5 个节点。
- 集群运行 100 个业务 Pod。
- Sidecar 每个 Pod 一个 Envoy。
- Ambient 每个节点一个 ztunnel。
- 另外有 3 个 Namespace 使用 Waypoint。
Ambient 的优势在于减少重复的 L4 代理开销,但 Waypoint 本身仍然需要 CPU 和内存,不能简单认为 Ambient 没有代理资源成本。