《云原生网络数据面可观测性最佳实践》——二、全景剖析阿里云容器网络数据链路——6. ASM Istio 模式架构设计(下)

简介: 《云原生网络数据面可观测性最佳实践》——二、全景剖析阿里云容器网络数据链路——6. ASM Istio 模式架构设计(下)

更多精彩内容,欢迎观看:

《云原生网络数据面可观测性最佳实践》——二、全景剖析阿里云容器网络数据链路——6. ASM Istio 模式架构设计(中):https://developer.aliyun.com/article/1221373?spm=a2c6h.13148508.setting.16.15f94f0eCydDfj


Bootstrap

Envoy的初始化配置,与前文中的envoy-rev0.json是一致的。其中

drainDuration —— 热重启期间Envoy关闭连接的时间(以秒为单位),默认是45s

parentShutdownDuration —— 热重启期间,在完全关闭父进程之前,等到的最大时间,默认60s。此数值应该大于drainDuration

 

terminationDrainDuration —— 默认5s。proxy在关闭之前,允许连接关闭时间。通过前文,我们知道pod流量先过istio再被转发到业务容器。当应用发版时候,如果保证现有连接优雅关闭,保证istio-proxy容器在业务容器完全关闭现有连接后,再退出是发版更新时候需要考虑的问题,此值是实现业务平滑更新需要考虑的。

image.png

static_resources

config_dump中静态资源,是来自envoy-rev0.json,

里面包含了prometheus_stats、agent、sds-grpc、xds-grpc和zipkin等配置

image.png

dynamic_resources

动态资源,是通过xDS接口下发到每个istio-proxy容器生效的ASM Istio的配置。也是上述reviews dr,vs配置后通过ASM管控侧下发的。我们接下来关注动态资源配置

Listeners

Envoy采用的listener 来接受到达Envoy的流量请求。Listener和IP Sock、Unix Domain Socket绑定,也可以不绑定到具体的端口,而是接收从其他listener转发来的流量。ASM Istio就是利用了Envoy listener的这一特性来实现转发给不同的服务请求交给不同的Listeners来处理。

 

还是以productpage访问reviews来举例,productpage访问的是reviews的9080端口,根据上文我们知道productpage container访问 外部的9080端口会被先转发到15001 端口,所以我们先看下15001的端口listeners。


VirtualOutbound Listeners

Envoy在15001 端口创建了Listeners,所有被iptables转发的对外请求都会被转到envoy的15001 端口。可以从配置看到,envoy接受到了流量后,并不会做相关的业务动作,而是根据 "use_original_dst": true, 这个配置,依据请求的目的端口转发到相应的listeners 进行处理。

image.png 

那么肯定有个疑问了,如果请求端口并没有配置相关listeners设置,流量该如何进行处理呢?这个取决于outboundTrafficPolicy配置,详情请见
https://istio.io/latest/docs/reference/config/istio.mesh.v1alpha1/#MeshConfig-OutboundTrafficPolicy-Mode


Name

Description

REGISTRY_ONLY

只有被注册到服务网格集群内的serviceentry才可以被成功转发出去。如果访问的目的端未被注册到服务网格集群内,请求会被转发到BlackHoleCLuster,由于找不到匹配的upstream host,则会被丢弃。

ALLOW_ANY

无论外部请求是否注册,都可以发送到目的地址。如果目的地址未被listeners,则会将流量转发到PassthroughCluster的TCP proxy filter,请求将会被发送到原始目的地址。

 

Outbound Listeners

outbound 监听命名是0.0.0.0_9080,表明发向任何IP地址的9080端口都被此监听涵盖。"bind_to_port”: false此值表明监听没有绑定到tcp端口,流量是有virtualOutbound转发而来的。

 

那么首先我们需要区别这个监听是为了入方向还是出方向呢?对于入方向,流量会经过15006端口的virtualInbound的listeners,是不会进入0.0.0.0_9080的listeners。

image.png

 

从配置上可以看到filter中并没有特殊的志敏筛选条件,说明接受任何流量,其中config_source 为ads,表明这个是来自动态发现。

 

根据前文可以可看到revirews,ratings,details几个service都是9080端口,这些应用都被同一个服务网格注入,那么productpage访问的目的地址的9080,Envoy如何刚知道是哪个service?是如何判断如果目的端口未9080的地址不是网格内,该如何处理呢?通过上图"route_config_name": "9080" 可以看到存在一个‘9080’的路由规则,在这个路由规则中规定不同的请求目的地的不同的处理结果,下一小节我们将讨论。

Route

前文我们已经知道productpage 应用访问reviews的9080端口会被listeners outbound 0.0.0.0_9080 路由规则到 9080的路由。以下是‘9080’ 路由的全部信息。我们可以看到一共有5个virtual_hosts,分别是allow_any、details、productpage、ratings、和reviews。其中后面4个对应4个不同outbound的cluster,allow_any 对应的是PassthroughCluster,当出方向请求找到相应的Cluster规则时候,会采用默认直接通过。

 

可能有小伙伴很奇怪productpage不直接调用ratings服务,为什么productpage envoy配置会包含ratings的信息。

 

这是因为ASM Istio控制面是无法感知到数据面各个服务之间是如何调用的,因此会将所有的配置信息都下发到被注入的envoy里面,这样保证了网格配置的一致性,但是随着网格服务配置的增多,每个envoy接受和本envoy不相关的配置信息就会变多,这样对envoy资源使用会有一定影响,如果小伙伴有很好的envoy开发能力,并且对业务之间调用非常熟悉,想去除掉本pod中envoy无关的规则,可以通过sidecar规则自定义配置对egress和ingress进行调整,详情请见:

https://istio.io/latest/docs/reference/config/networking/sidecar/

{
 "version_info": "2023-01-30T06:25:21Z/19",
 "route_config": {
 "@type": "type.googleapis.com/envoy.config.route.v3.RouteConfiguration",
 "name": "9080",
 "virtual_hosts": [
 {
 "name": "allow_any",
 "domains": [
 "*"
 ],
 "routes": [
 {
 "match": {
 "prefix": "/"
 },
 "route": {
 "cluster": "PassthroughCluster",
 "timeout": "0s",
 "max_grpc_timeout": "0s"
 },
 "name": "allow_any"
 }
 ],
 "include_request_attempt_count": true
 },
 {
 "name": "details.istio-inject.svc.cluster.local:9080",
 "domains": [
 "details.istio-inject.svc.cluster.local",
 "details.istio-inject.svc.cluster.local:9080",
 "details",
 "details:9080",
 "details.istio-inject.svc",
 "details.istio-inject.svc:9080",
 "details.istio-inject",
 "details.istio-inject:9080",
 "192.168.1.125",
 "192.168.1.125:9080"
 ],
 "routes": [
 {
 "match": {
 "prefix": "/"
 },
 "route": {
 "cluster": "outbound|9080||details.istio-inject.svc.cluster.local",
 "timeout": "0s",
 "retry_policy": {
 "retry_on": "connect-failure,refused-stream,unavailable,cancelled,retriable-status-codes",
 "num_retries": 2,
 "retry_host_predicate": [
 {
 "name": "envoy.retry_host_predicates.previous_hosts",
 "typed_config": {
 "@type": "type.googleapis.com/envoy.extensions.retry.host.previous_hosts.v3.PreviousHostsPredicate"
 }
 }
 ],
 "host_selection_retry_max_attempts": "5",
 "retriable_status_codes": [
 503
 ]
 },
 "max_stream_duration": {
 "max_stream_duration": "0s",
 "grpc_timeout_header_max": "0s"
 }
 },
 "decorator": {
 "operation": "details.istio-inject.svc.cluster.local:9080/*"
 },
 "name": "default"
 }
 ],
 "include_request_attempt_count": true
 },
 {
 "name": "istio-ingressgateway.istio-system.svc.cluster.local:9080",
 "domains": [
 "istio-ingressgateway.istio-system.svc.cluster.local",
 "istio-ingressgateway.istio-system.svc.cluster.local:9080",
 "istio-ingressgateway.istio-system",
 "istio-ingressgateway.istio-system:9080",
 "istio-ingressgateway.istio-system.svc",
 "istio-ingressgateway.istio-system.svc:9080",
 "192.168.1.250",
 "192.168.1.250:9080"
 ],
 "routes": [
 {
 "match": {
 "prefix": "/"
 },
 "route": {
 "cluster": "outbound|9080||istio-ingressgateway.istio-system.svc.cluster.local",
 "timeout": "0s",
 "retry_policy": {
 "retry_on": "connect-failure,refused-stream,unavailable,cancelled,retriable-status-codes",
 "num_retries": 2,
 "retry_host_predicate": [
 {
 "name": "envoy.retry_host_predicates.previous_hosts",
 "typed_config": {
 "@type": "type.googleapis.com/envoy.extensions.retry.host.previous_hosts.v3.PreviousHostsPredicate"
 }
 }
 ],
 "host_selection_retry_max_attempts": "5",
 "retriable_status_codes": [
 503
 ]
 },
 "max_stream_duration": {
 "max_stream_duration": "0s",
 "grpc_timeout_header_max": "0s"
 }
 },
 "decorator": {
 "operation": "istio-ingressgateway.istio-system.svc.cluster.local:9080/*"
 "name": "default"
 }
 ],
 "include_request_attempt_count": true
 },
 }, 
 {
 "name": "productpage.istio-inject.svc.cluster.local:9080",
 "domains": [
 "productpage.istio-inject.svc.cluster.local",
 "productpage.istio-inject.svc.cluster.local:9080",
 "productpage",
 "productpage:9080",
 "productpage.istio-inject.svc",
 "productpage.istio-inject.svc:9080",
 "productpage.istio-inject",
 "productpage.istio-inject:9080",
 "192.168.6.226",
 "192.168.6.226:9080"
 ],
 "routes": [
 {
 "match": {
 "prefix": "/"
 },
 "route": {
 "cluster": "outbound|9080||productpage.istio-inject.svc.cluster.local",
 "timeout": "0s",
 "retry_policy": {
 "retry_on": "connect-failure,refused-stream,unavailable,cancelled,retriable-status-codes",
 "num_retries": 2,
 "retry_host_predicate": [
 {
 "name": "envoy.retry_host_predicates.previous_hosts",
 "typed_config": {
 "@type": "type.googleapis.com/envoy.extensions.retry.host.previous_hosts.v3.PreviousHostsPredicate"
 }
 }
 ],
 "host_selection_retry_max_attempts": "5",
 "retriable_status_codes": [
 503
 ]
 },
 "max_stream_duration": {
 "max_stream_duration": "0s",
 "grpc_timeout_header_max": "0s"
 }
 },
 "decorator": {
 "operation": "productpage.istio-inject.svc.cluster.local:9080/*"
 },
 "name": "default"
 }
 ],
 "include_request_attempt_count": true
 },
 {
 "name": "ratings.istio-inject.svc.cluster.local:9080",
 "domains": [
 "ratings.istio-inject.svc.cluster.local",
 "ratings.istio-inject.svc.cluster.local:9080",
 "ratings",
 "ratings:9080",
 "ratings.istio-inject.svc",
 "ratings.istio-inject.svc:9080",
 "ratings.istio-inject",
 "ratings.istio-inject:9080",
 "192.168.1.172",
 "192.168.1.172:9080"
 ],
 "routes": [
 {
 "match": {
 "prefix": "/"
 },
 "route": {
 "cluster": "outbound|9080||ratings.istio-inject.svc.cluster.local",
 "timeout": "0s",
 "retry_policy": {
 "retry_on": "connect-failure,refused-stream,unavailable,cancelled,retriable-status-codes",
 "num_retries": 2,
 "retry_host_predicate": [
 {
 "name": "envoy.retry_host_predicates.previous_hosts",
 "typed_config": {
 "@type": "type.googleapis.com/envoy.extensions.retry.host.previous_hosts.v3.PreviousHostsPredicate"
 }
 }
 ],
 "host_selection_retry_max_attempts": "5",
 "retriable_status_codes": [
 503
 ]
 },
 "max_stream_duration": {
 "max_stream_duration": "0s",
 "grpc_timeout_header_max": "0s"
 }
 },
 "decorator": {
 "operation": "ratings.istio-inject.svc.cluster.local:9080/*"
 },
 "name": "default"
 }
 ],
 "include_request_attempt_count": true
 },
 {
 "name": "reviews.istio-inject.svc.cluster.local:9080",
 "domains": [
 "reviews.istio-inject.svc.cluster.local",
 "reviews.istio-inject.svc.cluster.local:9080",
 "reviews",
 "reviews:9080",
 "reviews.istio-inject.svc",
 "reviews.istio-inject.svc:9080",
 "reviews.istio-inject",
 "reviews.istio-inject:9080",
 "192.168.4.113",
 "192.168.4.113:9080"
 ],
 "routes": [
 {
 "match": {
 "prefix": "/"
 },
 "route": {
 "weighted_clusters": {
 "clusters": [
 {
 "name": "outbound|9080|v1|reviews.istio-inject.svc.cluster.local",
 "weight": 10
 },
 {
 "name": "outbound|9080|v2|reviews.istio-inject.svc.cluster.local",
 "weight": 40
 },
 {
 "name": "outbound|9080|v3|reviews.istio-inject.svc.cluster.local",
 "weight": 50
 }
 ],
 "total_weight": 100
 },
 "timeout": "0s",
 "retry_policy": {
 "retry_on": "connect-failure,refused-stream,unavailable,cancelled,retriable-status-codes",
 "num_retries": 2,
 "retry_host_predicate": [
 {
 "name": "envoy.retry_host_predicates.previous_hosts",
 "typed_config": {
 "@type": "type.googleapis.com/envoy.extensions.retry.host.previous_hosts.v3.PreviousHostsPredicate"
 }
 }
 ],
 "host_selection_retry_max_attempts": "5",
 "retriable_status_codes": [
 503
 ]
 },
 "max_stream_duration": {
 "max_stream_duration": "0s",
 "grpc_timeout_header_max": "0s"
 }
 },
 "metadata": {
 "filter_metadata": {
 "istio": {
 "config": "/apis/networking.istio.io/v1alpha3/namespaces/istio-inject/virtual-service/reviews"
 }
 }
 },
 "decorator": {
 "operation": "reviews:9080/*"
 },
 "name": "route"
 }
 ],
 "include_request_attempt_count": true
 }
 ],
 "validate_clusters": false
 },
 "last_updated": "2023-01-30T06:25:21.804Z"
 },

 我们还是以productpage调用reviews来举例,Envoy 会根据 HTTP header 中的domains 来匹配 VirtualHost中domain,所以可以看到domains中列举了reviews的集群内的长短域名,和svc的地址。match “/” 会路由到三个Cluster "outbound|9080|v1|reviews.istio-inject.svc.cluster.local"、"outbound|9080|v2|reviews.istio-inject.svc.cluster.local"和"outbound|9080|v3|reviews.istio-inject.svc.cluster.local",权重分别为10,40,50,名称是‘route’,看到这里是不是有点熟悉?

 

对的,这和前文 [1.3 Envoy配置简读-背景] 中 reviews的VS中的设置,故我们在vs中的相关配置信息,最终envoy会转为route的配置加载后生效。

image.png

image.png

 

 

 通过前面我们还可以看到默认超时是0s,默认重试次数是2次,重试条件是"connect-failure,refused-stream,unavailable,cancelled,retriable-status-codes"

 

Cluster

outbound cluster

 

根据上一下小节,productpage访问reviews,会被productpage中的istio-proxy匹配到‘9080’路由-> 依据vs配置的相关信息,进入三个cluster( "outbound|9080|v1|reviews.istio-inject.svc.cluster.local"、"outbound|9080|v2|reviews.istio-inject.svc.cluster.local"和"outbound|9080|v3|reviews.istio-inject.svc.cluster.local")中一个。

 

这里我们就以"outbound|9080|v1|reviews.istio-inject.svc.cluster.local"Cluster 为例

 image.png

image.png

outbound|9080|v1|reviews.istio-inject.svc.cluster.local cluster配置中可以看到,其类型为EDS,即表示该Cluster的endpoint来自于动态发现,动态发现中eds_config则表明是由ads下发的。同样可以看到与前文 [1.3 Envoy配置简读-背景] 中 reviews的dr中的设置熟悉的配置,比如connectionpool,outlierDetection等这些相关配置信息,最终envoy会转为cluster的配置加载后生效。

 

接下来我们稍微探讨下其他几个特殊的cluster。

BlackHoleCluster

Envoy对于找不到后端处理请求的会默认丢弃,所以会有统一的一个blackholecluster,没有任何指明的后端svc。任何无匹配后端的流量会被转发到这个cluster。

image.png


PassthroughCluster

和BlackHoleCluter正好相反,发向PassthroughCluster的请求会被直接发送到器请求连接中的原始目地的,type类型是"type": "ORIGINAL_DST",表明其发到原始的目的地址:端口

 image.png


Inbound Cluster

inbound Cluster是为了pod上的入方向的请求,对于reviews来说,其对应的Inbound Cluster只有一个inbound|9080。

 image.png


Endpoint

从endpoint文件内容可以看到,

reviews Cluster “outbound|9080|v1|reviews.istio-inject.svc.cluster.local”只有1 个endpoint地址,是reviews-v1-74fb8fdbd8-qwsjqpod ip 10.0.3.29

 image.png

image.png

 

至此,我们大概梳理完毕服务网格内两个服务之间访问,istio-proxy日志解读和配置对应关系。

 

6) Tips

前文的config_dump文件太长,解读起来其实比较费力,服务网格提供了asmctl工具可以很方便的去解读listeners,route,cluster,endpoint等,详细信息请见
https://help.aliyun.com/document_detail/313187.html

[root@shycmain ~]# asmctl --asmconfig asmconfig pc listeners productpage-v1-797d845774-dndmk.istio-inject --port 9080
ADDRESS PORT MATCH DESTINATION
0.0.0.0 9080 Trans: raw_buffer; App: HTTP Route: 9080
0.0.0.0 9080 ALL PassthroughCluster
[root@shycmain ~]# asmctl --asmconfig asmconfig pc routes productpage-v1-797d845774-dndmk.istio-inject --name 9080
NOTE: This output only contains routes loaded via RDS.
NAME DOMAINS MATCH VIRTUAL SERVICE
9080 details /*
9080 istio-ingressgateway.istio-system /*
9080 productpage /*
9080 ratings /*
9080 reviews /* reviews.istio-inject
[root@shycmain ~]# asmctl --asmconfig asmconfig pc Cluster productpage-v1-797d845774-dndmk.istio-inject --fqdn reviews.istio-inject.svc.cluster.local
SERVICE FQDN PORT SUBSET DIRECTION TYPE DESTINATION RULE
reviews.istio-inject.svc.cluster.local 9080 - outbound EDS reviews.istio-inject
reviews.istio-inject.svc.cluster.local 9080 v1 outbound EDS reviews.istio-inject
reviews.istio-inject.svc.cluster.local 9080 v2 outbound EDS reviews.istio-inject
reviews.istio-inject.svc.cluster.local 9080 v3 outbound EDS reviews.istio-inject
[root@shycmain ~]# asmctl --asmconfig asmconfig pc endpoint productpage-v1-797d845774-dndmk.istio-inject --Cluster "outbound|9080|v1|reviews.istio-inject.svc.cluster.local"
ENDPOINT STATUS OUTLIER CHECK CLUSTER
10.0.3.29:9080 HEALTHY OK outbound|9080|v1|reviews.istio-inject.svc.cluster.local

 7) 小结

本篇文章主要聚焦ASM Istio服务网格模式下,被注入pod的数据面流量转发链路情况。istio灵活注入实现了在Pod维度对流量的定制化配置和观测性,带来了业务链路角度实现的更多种的可能。在服务网格中配置gateway,virtualservice,destinationrule等规则在通过xDS下发到envoy后,会通过listeners,route、cluster、endpoint多个环节最终体现在流量转发规则上

 

那么在运用ASM遇到不符合预期情况时,这些环节都是需要考虑的方向。ASM 除了流量管理,还有安全,鉴权,可观测方面的便捷运用,这些方面的配置,最终也会体现在相关的网格服务资源配置上,感兴趣的小伙伴可以参考ASM官方文档

相关文章
|
存储 Cloud Native 数据处理
从嵌入式状态管理到云原生架构:Apache Flink 的演进与下一代增量计算范式
本文整理自阿里云资深技术专家、Apache Flink PMC 成员梅源在 Flink Forward Asia 新加坡 2025上的分享,深入解析 Flink 状态管理系统的发展历程,从核心设计到 Flink 2.0 存算分离架构,并展望未来基于流批一体的通用增量计算方向。
448 0
从嵌入式状态管理到云原生架构:Apache Flink 的演进与下一代增量计算范式
|
6月前
|
运维 监控 Cloud Native
从本土到全球,云原生架构护航灵犀互娱游戏出海
本文内容整理自「 2025 中企出海大会·游戏与互娱出海分论坛」,灵犀互娱基础架构负责人朱晓靖的演讲内容,从技术层面分享云原生架构护航灵犀互娱游戏出海经验。
593 15
|
6月前
|
运维 监控 Cloud Native
从本土到全球,云原生架构护航灵犀互娱游戏出海
内容整理自「 2025 中企出海大会·游戏与互娱出海分论坛」,灵犀互娱基础架构负责人朱晓靖的演讲内容,从技术层面分享云原生架构护航灵犀互娱游戏出海经验。
|
10月前
|
运维 Cloud Native 测试技术
极氪汽车云原生架构落地实践
随着极氪数字业务的飞速发展,背后的 IT 技术也在不断更新迭代。极氪极为重视客户对服务的体验,并将系统稳定性、业务功能的迭代效率、问题的快速定位和解决视为构建核心竞争力的基石。
|
4月前
|
Kubernetes Cloud Native 区块链
Arista cEOS 4.35.0F 发布 - 针对云原生环境设计的容器化网络操作系统
Arista cEOS 4.35.0F 发布 - 针对云原生环境设计的容器化网络操作系统
184 0
|
4月前
|
人工智能 Kubernetes Cloud Native
Higress(云原生AI网关) 架构学习指南
Higress 架构学习指南 🚀写在前面: 嘿,欢迎你来到 Higress 的学习之旅!
1238 0
|
7月前
|
运维 监控 Cloud Native
从“守机器”到“写策略”——云原生架构把运维逼成了架构师
从“守机器”到“写策略”——云原生架构把运维逼成了架构师
181 1
|
9月前
|
存储 缓存 分布式计算
StarRocks x Iceberg:云原生湖仓分析技术揭秘与最佳实践
本文将深入探讨基于 StarRocks 和 Iceberg 构建的云原生湖仓分析技术,详细解析两者结合如何实现高效的查询性能优化。内容涵盖 StarRocks Lakehouse 架构、与 Iceberg 的性能协同、最佳实践应用以及未来的发展规划,为您提供全面的技术解读。 作者:杨关锁,北京镜舟科技研发工程师
StarRocks x Iceberg:云原生湖仓分析技术揭秘与最佳实践
|
9月前
|
人工智能 Cloud Native 容灾
深圳农商银行三代核心系统全面投产 以云原生架构筑牢数字化转型基石
深圳农商银行完成第三代核心系统全面上云,日均交易超3000万笔,峰值处理效率提升2倍以上。扎根深圳70余年,与阿里云共建“两地三中心”分布式云平台,实现高可用体系及全栈护航。此次云原生转型为行业提供可复制样本,未来将深化云计算与AI合作,推动普惠金融服务升级。
654 17
|
9月前
|
存储 Cloud Native 关系型数据库
PolarDB开源:云原生数据库的架构革命
本文围绕开源核心价值、社区运营实践和技术演进路线展开。首先解读存算分离架构的三大突破,包括基于RDMA的分布式存储、计算节点扩展及存储池扩容机制,并强调与MySQL的高兼容性。其次分享阿里巴巴开源治理模式,涵盖技术决策、版本发布和贡献者成长体系,同时展示企业应用案例。最后展望技术路线图,如3.0版本的多写多读架构、智能调优引擎等特性,以及开发者生态建设举措,推荐使用PolarDB-Operator实现高效部署。
450 4