SlideShare a Scribd company logo
1 of 54
Download to read offline
GOLANG TAIWAN GATHERING #77 X CNTUG
探索 ISTIO 新型 DATA PLANE 架構
AMBIENT MESH
演講者:耿映翔 演講日期:2023/12/14 演講地點:天瓏書局
Service Mesh
OUTLINE
自我介紹
動機 Ambient Mesh 運作原理
結論
Ambient Mesh
耿映翔 (阿皮)
主要以 Golang、Vuejs 作為主力開發工具
目前就讀於 彰師大 數科所 (快畢業ㄌ)
go-zero, ants-pool Contributor
Email: zxc752166@gmail.com
自我介紹
動機
• Golang 微服務
• 需要設定 Platform 層的瑣碎功能
• The more microservices we have, the more
difficult it is for developers to configure
參考資料:[1]、[2]
平台層負責功能
Kubernetes and Istio
• Golang 微服務
• Service Mesh Implement Functions of
Communication in Infra
• Developers focus on Business logic
+Kubernetes +Istio Service Mesh
SERVICE MESH? AMBIENT MESH?
Service Mesh:
• A infrastructure layer for handling service-to-service communication.
• It’s responsible for the reliable delivery of requests through the complex topology of
services that comprise a modern, cloud native application.
Ambient Mesh:
• The new architectural alternative that does not rely on sidecars for a service mesh.
• Enables customers to reduce costs up to 90% while simplifying operations and improving
performance for their applications.
參考資料:[3]、[4]
ISTIO SERVICE MESH
• Control Plane
⚬ Pilot:管理 Proxy 路由規則配置
⚬ Citadel:憑證授權單位 (CA)
⚬ Galley: 配置驗證、提取、處理
• Data Plane
⚬ Sidecar:使用 Envoy (c++ based) 作為
Proxy,攔截 Pod Inbound / Outbound
流量
參考資料:[5]
SIDECAR PROXY
• Init Container 會使用 IPtables 配置來
kernel 網路規則
• kernel space 與 user space 反覆切換
(同一節點內,至少3次)
Init
Container
Init
Container
參考資料:[6]
Security
Observability
Traffic
Management
#mTLS
BENEFITS OF SERVICE MESH
#Authorization
#Metrics #Distributed Traces #Access Logs
#Service Discovery
#Retry
#Rate Limiting
#Timeout
#Fault Injection
#Circuit Breaker
#Diverse Deployment Policies
#Load Balancing
• Blue Green Deployment
• Canary Deployment
• A/B Testing
Security #mTLS
BENEFITS OF SERVICE MESH
#Authorization
Observability
BENEFITS OF SERVICE MESH
#Metrics #Distributed Traces #Access Logs
參考資料:[7]
Observability
BENEFITS OF SERVICE MESH
#Metrics #Distributed Traces #Access Logs
參考資料:[8]
BENEFITS OF SERVICE MESH
Traffic
Management
#Service Discovery
#Retry
#Rate Limiting
#Timeout
#Fault Injection
#Circuit Breaker
#Diverse Deployment Policies
#Load Balancing
CHALLENGES OF SERVICE MESH
• Sidecar Proxy 無法完全被 Controller Manager (Kubernetes) 的生命週期所控制
⚬ solution: readiness probe or liveness probe
參考資料:[9]、[10]、[11]、[12]
CHALLENGES OF SERVICE MESH
• Job 會等待所有容器停止才會銷毀
• Job 資源在執行時,如果被注入 Sidecar,會
導致無法被完整的銷毀,持續占用資源
CHALLENGES OF SERVICE MESH
• Sidecar 版本升級,要重新部署微服務,可能導致服務不可用
CHALLENGES OF SERVICE MESH
• 對於 non-HTTP 請求支援非常有限,可能還需要 Aeraki([Air-rah-ki]) Mesh 支援
• 每個 Pod 都會有一個 Sidecar Proxy,一旦 Pod 越多,占用資源也越高
ISTIO AMBIENT MESH
● Sidecar-less 的 data plane 部署模型
● 將 Sidecar Proxy 以 L4 和 L7 的功能進行
分割,並獨立部署
○ ztunnel (DaemonSet)
○ waypoint proxy (Gateway)
● 使用 HBONE 協議對流量進行封裝
參考資料:[6]、[13]、[14]
L4 & L7 PROXY
BENEFITS OF AMBIENT MESH
• 保留原本 Service Mesh 所提供的功能
• 改善注入 Sidecar,生命週期無法控制的問題
• 使用 HBONE 建立 tunnel 對流量進行簡易封
裝,不會有流量中斷問題
• Proxy 獨立部署,服務與 Proxy 不互相影響
• Proxy 數量減少,降低 Sidecar 部署的成本
Packet Flow
服務彼此不在同節點上 服務彼此在同一個節點上
Ztunnel Packet Flow
服務彼此不在同節點上 服務彼此在同一個節點上
Ztunnel + Waypoint Packet Flow
• Waypoint Proxy 可以根據 Namespace 或是 ServiceAccount 來進行部署
Where is Waypoint Proxy?
Ztunnel Configuration
$ kubectl exec -n istio-system ztunnel-bdqms -c istio-proxy -- curl
"127.0.0.1:15000/config_dump?include_eds"
"by_addr": {
"/10.244.2.5": {
"workloadIps": [
"10.244.2.5"
],
"waypoint": {
"destination": "/10.96.183.171",
"port": 15008
},
"protocol": "TCP",
"uid": "Kubernetes//Pod/default/httpbin-86869bccff-8v829",
"name": "httpbin-86869bccff-8v829",
"namespace": "default",
"trustDomain": "cluster.local",
"serviceAccount": "httpbin",
"workloadName": "httpbin",
"workloadType": "deployment",
"canonicalName": "httpbin",
"canonicalRevision": "v1",
"node": "ambient-worker2",
"status": "Healthy",
"clusterId": "Kubernetes"
},
// ...
}
註:XDS 是用於動態配置 Proxy 的傳輸協議
Environment Setup
$ kind create cluster --config ./deployment/kind-cluster.yaml --name ambient
$ k get node -o wide
NAME STATUS ROLES AGE VERSION INTERNAL-IP …
ambient-control-plane Ready control-plane 4m14s v1.27.3 172.18.0.3 …
ambient-worker Ready <none> 3m49s v1.27.3 172.18.0.4 …
ambient-worker2 Ready <none> 3m49s v1.27.3 172.18.0.2 …
$ k apply -f ./istio-1.19.0/samples/sleep/sleep.yaml
k apply -f ./istio-1.19.0/samples/httpbin/httpbin.yaml
serviceaccount/sleep created
service/sleep created
deployment.apps/sleep created
serviceaccount/httpbin created
service/httpbin created
deployment.apps/httpbin created
$ istioctl install --set profile=ambient -y
Istio CNI 元件 (CNI Network Plugin)
• 以 DaemonSet 佈署於各節點
• 監聽節點和 Pod 變化
• 節點:建立 IPSet 和網路介面,設定 IPTables
和路由規則
• ztunnel Pod:設定 IPTables 和路由規則
• 轉發方式:
⚬ iptables + Geneve tunnel (default)
⚬ ebpf
參考資料:[6]
1. 建立 IPSet
● 紀錄當前 Node 上 Pods 的 IP Address
● Istio-CNI 根據異動,自動進行更新
● 用途:當封包的 srcIP 命中此集合,將會被標記
metadata (0x100/0x100)。
$ docker exec ambient-worker ipset list
Name: ztunnel-pods-ips
Type: hash:ip
Revision: 0
Header: family inet hashsize 1024 maxelem 65536
Size in memory: 296
References: 1
Number of entries: 1
Members:
10.244.1.7 ambient-worker 的 Pod IP Address
$ k get pod
-ocustom-columns=NAME:.metadata.name,IP:.status.podIP,NODE:.spec.nodeN
ame|grep ambient-worker
httpbin-86869bccff-8v829 10.244.2.5 ambient-worker2
sleep-9454cc476-w74cd 10.244.1.7 ambient-worker
2. 建立 Network Interface (Node)
$ docker exec ambient-worker ip addr|grep istioin
5: istioin: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1450 qdisc noqueue state UNKNOWN group default
inet 192.168.126.1/30 brd 192.168.126.3 scope global istioin
$ docker exec ambient-worker ip addr|grep istioout
6: istioout: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1450 qdisc noqueue state UNKNOWN group default
inet 192.168.127.1/30 brd 192.168.127.3 scope global istioou
• 使用 ptp (point to point) 模式連接
• 添加 istioin 網路介面,IP: 192.168.126.1
• 添加 istioout 網路介面,IP: 192.168.127.1
2. 建立 Network Interface (Pod)
$ k -n istio-system exec ztunnel-cmq4f -- ip addr|grep pistioin
3: pistioin: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1450 qdisc noqueue state UNKNOWN group default
inet 192.168.126.2/30 brd 192.168.126.3 scope global pistioin
$ k -n istio-system exec ztunnel-cmq4f -- ip addr|grep pistioout
4: pistioout: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1450 qdisc noqueue state UNKNOWN group default
inet 192.168.127.2/30 brd 192.168.127.3 scope global pistioout
• 添加 pistioin 網路介面,IP: 192.168.126.2
• 添加 pistioout 網路介面,IP: 192.168.127.2
2. 建立 Network Interface
$ docker exec ambient-worker ip -d link show istioout
9: istioout: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1450 qdisc noqueue state UNKNOWN mode DEFAULT
group default
link/ether ae:b7:c1:b2:00:4d brd ff:ff:ff:ff:ff:ff promiscuity 0 minmtu 68 maxmtu 65485
geneve id 1001 remote 10.244.1.6 ttl auto dstport 6081 noudpcsum udp6zerocsumrx addrgenmode eui64
numtxqueues 1 numrxqueues 1 gso_max_size 65536 gso_max_segs 65535
$ k -n istio-system exec ztunnel-cmq4f -- ip -d link show pistioout
4: pistioout: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1450 qdisc noqueue state UNKNOWN mode DEFAULT
group default
link/ether 5e:d6:87:52:61:97 brd ff:ff:ff:ff:ff:ff promiscuity 0 minmtu 68 maxmtu 65485
geneve id 1001 remote 10.244.1.1 ttl auto dstport 6081 noudpcsum udp6zerocsumrx addrgenmode eui64
numtxqueues 1 numrxqueues 1 gso_max_size 65536 gso_max_segs 65535
• istioout 和 istioin 所接收的封包,將會經由 Geneve Tunnel 被傳入 ztunnel Pod 之中
,也就是 10.244.1.6
3. 設定 Network Interface
● 將 rp_filter 設定為 0,關閉反向路徑過濾
• 1: 嚴格模式,反向路徑若不是同一個網路介面,直接丟棄封包
• 2: 寬鬆模式,反向路徑的封包如果不可到達 (任意介面),就會被丟棄
● 將 accept_local 設定為 1
• 接受非 loopback 介面傳遞的封包 (srcIP 是 local)
accept_local – BOOLEAN
Accept packets with local source addresses. In combination with suitable routing, this
can be used to direct packets between two local interfaces over the wire and have them
accepted properly. default FALSE
4. 設定 IPTables、路由規則 ● 更改 IPTables 上的 NAT 和 MANGLE 表
• NAT:用於更改 srcIP 和 dstIP
• MANGLE:用於標記 metadata
$ docker exec ambient-worker ip rule
0: from all lookup local
100: from all fwmark 0x200/0x200 goto 32766
101: from all fwmark 0x100/0x100 lookup 101
102: from all fwmark 0x40/0x40 lookup 102
103: from all lookup 100
32766: from all lookup main
32767: from all lookup default
$ docker exec ambient-worker ip route show table 101
default via 192.168.127.2 dev istioout
10.244.1.6 dev veth6f1f20dc scope link
實際執行 sleep 發送請求至 httpbin
參考資料:[15]、[16]
1. Sleep NS -> Node NS (Mangle)
$ docker exec ambient-worker iptables-save
--- mangle —
# 原本正在執行的 PREROUTING chain 跳至 ztunnel-PREROUTING chain
-A PREROUTING -j ztunnel-PREROUTING
# ztunnel-PREROUTING chain 規則
# …
-A ztunnel-PREROUTING -m mark --mark 0x200/0x200 -j RETURN
-A ztunnel-PREROUTING -p tcp -m set --match-set ztunnel-pods-ips src -j MARK --set-xmark 0x100/0x100
● 原本 PREROUTING chain 跳至 ztunnel-PREROUTING chain
● 遇到 tcp 的請求,查找 ztunnel-pods-ips 配對 srcIP,有配對成功就標記 0x100/0x100
1. Sleep NS -> Node NS (NAT)
$ docker exec ambient-worker iptables-save
--- nat —
-A PREROUTING -j ztunnel-PREROUTING
# 將 ClusterIP dnat 成 PodIP
-A PREROUTING -m comment --comment "kubernetes service portals" -j KUBE-SERVICES
# 在 ztunnel-PREROUTING chain ACCEPT,所以不會進入 KUBE-SERVICES chain
-A ztunnel-PREROUTING -m mark --mark 0x100/0x100 -j ACCEPT
● 原本 PREROUTING chain 跳至 ztunnel-PREROUTING chain
● 讓帶有 0x100/0x100 標記的封包直接通過,前往路由轉發
2. Node NS (NAT) -> Ztunnel NS
# 查看路由規則
$ docker exec ambient-worker ip rule
0: from all lookup local
100: from all fwmark 0x200/0x200 goto 32766
101: from all fwmark 0x100/0x100 lookup 101
102: from all fwmark 0x40/0x40 lookup 102
103: from all lookup 100
32766: from all lookup main
32767: from all lookup default
● 路由規則內會命中 fwmark 0x100/0x100 的標記
● 將封包由 istioout 網路介面進行傳送至 192.168.127.2 的 pistioout 網路介面
# 根據 fwmark 0x100/0x100,查找 table 101
$ docker exec ambient-worker ip route show table 101
default via 192.168.127.2 dev istioout
10.244.1.6 dev veth6f1f20dc scope link
3. Ztunnel NS -> Other Node
# 獲取 ztunnel Pod 內的 iptables 規則
$ k -n istio-system exec ztunnel-cmq4f -- iptables-save
--- mangle ---
# …
# 使用 TPORXY 作為轉發,並標記 port, ip, tproxy-mark,用做後
續路由規則中使用
-A PREROUTING -i pistioout -p tcp -j TPROXY --on-port
15001 --on-ip 127.0.0.1 --tproxy-mark 0x400/0xfff
# 獲取 ztunnel Pod 內的路由規則
$ k -n istio-system exec ztunnel-cmq4f -- ip rule
0: from all lookup local
20000: from all fwmark 0x400/0xfff lookup 100
20003: from all fwmark 0x4d3/0xfff lookup 100
32766: from all lookup main
32767: from all lookup default
$ k -n istio-system exec ztunnel-bbplk -- ip route show table 100
local default dev lo scope host
● 使用 Transparent Proxy 重新導向 127.0.0.1:15001,保留原本的 dstIP
● 將封包由 loopback 網路介面傳送到 ztunnel 的 Process
3. Ztunnel NS -> Other Node
3. Ztunnel NS -> Other Node
1. Node NS -> Ztunnel NS
$ docker exec ambient-worker2 ip rule
0: from all lookup local
100: from all fwmark 0x200/0x200 goto 32766
101: from all fwmark 0x100/0x100 lookup 101
102: from all fwmark 0x40/0x40 lookup 102
103: from all lookup 100
32766: from all lookup main
32767: from all lookup default
● 入站流量不會命中 ztunnel-pods-ips,所以直接進入路由轉發
● 將封包由 istioin 網路介面進行傳送至 192.168.126.2 的 pistioin 網路介面
$ docker exec ambient-worker2 ip route show table 100
10.244.2.5 via 192.168.126.2 dev istioin src 10.244.2.1
10.244.2.10 dev veth6cc9a213 scope link
2. Ztunnel NS
# 獲取 ztunnel Pod 內的 iptables 規則
$ k -n istio-system exec ztunnel-bbplk -- iptables-save
--- mangle ---
# 使用 TPORXY 作為轉發,並標記 port, ip, tproxy-mark,用做後續路
由規則中使用
-A PREROUTING -i pistioin -p tcp -m tcp --dport 15008 -j
TPROXY --on-port 15008 --on-ip 127.0.0.1 --tproxy-mark
0x400/0xfff
-A PREROUTING -i pistioin -p tcp -j TPROXY --on-port 15006
--on-ip 127.0.0.1 --tproxy-mark 0x400/0xfff
# 獲取 ztunnel Pod 內的路由規則
$ k -n istio-system exec ztunnel-bbplk -- ip rule
0: from all lookup local
20000: from all fwmark 0x400/0xfff lookup 100
20003: from all fwmark 0x4d3/0xfff lookup 100
32766: from all lookup main
32767: from all lookup default
$ k -n istio-system exec ztunnel-bbplk -- ip route show table 100
local default dev lo scope host
● 判斷目標端口是否為 15008,是代表有 TLS,否則是明文,一樣使用 Transparent Proxy
● 將封包由 loopback 網路介面傳送到 ztunnel 的 Process
3. Ztunnel NS -> Httpbin NS
3. Ztunnel NS -> Httpbin NS
CONCLUSION
● Ambient Mesh 特點
• Proxy 獨立部署,免除生命週期不可控問題和 istio 升級問題
• 使用 HBONE 協議,避免不支援協議的流量中斷問題
• Proxy 可以按需擴充,降低運算資源的成本
● Ambient Mesh 攔截方式
• 透過 IPSet、IPTables、路由規則轉發至 istioin/istioout 網路介面
• 使用 Geneve Tunnel 讓節點與 zutnnel Pod 之間的網路介面進行連接
• 使用 TProxy 傳輸 Pod 到 ztunnel Process 之間的流量
• 使用 HBONE 協議建立 Tunnel 安全傳輸 TCP 流量
REFERENCES
[1] 微服務實踐。https://hackmd.io/@maxcian/microservices-in-practices
[2] 如何透過 Go-kit 快速搭建微服務架構應用程式實戰 | GopherCon TW 2020。https://www.youtube.com/watch?v=tcfVgusbqy0。
[3] Service Mesh。https://www.techtarget.com/searchitoperations/definition/service-mesh。
[4] Ambient Mesh。https://www.solo.io/products/ambient-mesh/。
[5] Istio Architecture。https://istio.io/latest/docs/ops/deployment/architecture/。
[6] 如何构建 Sidecarless 模式的高性能服务网格。https://www.cnblogs.com/alisystemsoftware/p/17654717.html。
[7] Grafana vs Prometheus。https://blog.knoldus.com/grafana-vs-prometheus/。
[8] Jaeger Tracing: A Friendly Guide for Beginners。
https://medium.com/jaegertracing/jaeger-tracing-a-friendly-guide-for-beginners-7b53a4a568ca。
[9] Istio’s networking: An in-depth look at traffic and architecture。 https://www.solo.io/blog/istios-networking-in-depth/。
[10] Istio Ambient Explained。https://www.oreilly.com/library/view/istio-ambient-explained/9781098142698/ch01.html。
[11] Istio Sidecar注入原理。https://haoyunlaile.github.io/2020/istio/istio-sidecar-injector/。
[12] Kubernetes 特性调研: Sidecar Containers。https://zhuanlan.zhihu.com/p/369371749。
[13] Introducing Ambient Mesh。https://istio.io/latest/blog/2022/introducing-ambient-mesh/。
[14] Istio Ambient 模式流量管理实现机制详解(一)。https://www.zhaohuabing.com/post/2022-09-11-ambient-deep-dive-1/。
[15] SDN x Cloud Native Meetup - Webinar 邱牛上菜 #1 IPTABLES I。https://youtu.be/y4e_B6PdX8A?si=POt8bI8MMIn39KMi。
[16] 全网最细-深度解析 Istio Ambient Mesh 流量路径。https://www.cnblogs.com/alisystemsoftware/p/17760960.html。
THANK YOU

More Related Content

Similar to 探索 ISTIO 新型 DATA PLANE 架構 AMBIENT MESH - GOLANG TAIWAN GATHERING #77 X CNTUG

Ceph Day Shanghai - Ceph in Chinau Unicom Labs
Ceph Day Shanghai - Ceph in Chinau Unicom LabsCeph Day Shanghai - Ceph in Chinau Unicom Labs
Ceph Day Shanghai - Ceph in Chinau Unicom LabsCeph Community
 
Avm2虚拟机浅析与as3性能优化
Avm2虚拟机浅析与as3性能优化Avm2虚拟机浅析与as3性能优化
Avm2虚拟机浅析与as3性能优化Harvey Zhang
 
从林书豪到全明星 - 虎扑网技术架构如何化解流量高峰
从林书豪到全明星 - 虎扑网技术架构如何化解流量高峰从林书豪到全明星 - 虎扑网技术架构如何化解流量高峰
从林书豪到全明星 - 虎扑网技术架构如何化解流量高峰Scourgen Hong
 
服务器基准测试-叶金荣@CYOU-20121130
服务器基准测试-叶金荣@CYOU-20121130服务器基准测试-叶金荣@CYOU-20121130
服务器基准测试-叶金荣@CYOU-20121130Jinrong Ye
 
Monitor is all for ops
Monitor is all for opsMonitor is all for ops
Monitor is all for ops琛琳 饶
 
基于Innodb开发的最佳实践
基于Innodb开发的最佳实践基于Innodb开发的最佳实践
基于Innodb开发的最佳实践wubx
 
Avm2虚拟机浅析与as3性能优化(陈士凯)
Avm2虚拟机浅析与as3性能优化(陈士凯)Avm2虚拟机浅析与as3性能优化(陈士凯)
Avm2虚拟机浅析与as3性能优化(陈士凯)FLASH开发者交流会
 
[Flash开发者交流][2010.05.30]avm2虚拟机浅析与as3性能优化(陈士凯)
[Flash开发者交流][2010.05.30]avm2虚拟机浅析与as3性能优化(陈士凯)[Flash开发者交流][2010.05.30]avm2虚拟机浅析与as3性能优化(陈士凯)
[Flash开发者交流][2010.05.30]avm2虚拟机浅析与as3性能优化(陈士凯)Shanda innovation institute
 
Java线上应用问题排查方法和工具(空望)
Java线上应用问题排查方法和工具(空望)Java线上应用问题排查方法和工具(空望)
Java线上应用问题排查方法和工具(空望)ykdsg
 
全端物聯網探索之旅 - 重點整理版
全端物聯網探索之旅 - 重點整理版全端物聯網探索之旅 - 重點整理版
全端物聯網探索之旅 - 重點整理版Simen Li
 
Beyond rails server
Beyond rails serverBeyond rails server
Beyond rails serverMichael Chen
 
Hadoop+spark實作
Hadoop+spark實作Hadoop+spark實作
Hadoop+spark實作FEG
 
Puppet安装总结
Puppet安装总结Puppet安装总结
Puppet安装总结Yiwei Ma
 
Mysql proxy+mysql-mmm
Mysql proxy+mysql-mmmMysql proxy+mysql-mmm
Mysql proxy+mysql-mmmYiwei Ma
 
Module 08 防火牆
Module 08 防火牆Module 08 防火牆
Module 08 防火牆rbk19871124
 
Lvs在大规模网络环境下的应用pukong
Lvs在大规模网络环境下的应用pukongLvs在大规模网络环境下的应用pukong
Lvs在大规模网络环境下的应用pukongMichael Zhang
 
Python 于 webgame 的应用
Python 于 webgame 的应用Python 于 webgame 的应用
Python 于 webgame 的应用勇浩 赖
 

Similar to 探索 ISTIO 新型 DATA PLANE 架構 AMBIENT MESH - GOLANG TAIWAN GATHERING #77 X CNTUG (20)

Ceph Day Shanghai - Ceph in Chinau Unicom Labs
Ceph Day Shanghai - Ceph in Chinau Unicom LabsCeph Day Shanghai - Ceph in Chinau Unicom Labs
Ceph Day Shanghai - Ceph in Chinau Unicom Labs
 
Rootkit 101
Rootkit 101Rootkit 101
Rootkit 101
 
Avm2虚拟机浅析与as3性能优化
Avm2虚拟机浅析与as3性能优化Avm2虚拟机浅析与as3性能优化
Avm2虚拟机浅析与as3性能优化
 
从林书豪到全明星 - 虎扑网技术架构如何化解流量高峰
从林书豪到全明星 - 虎扑网技术架构如何化解流量高峰从林书豪到全明星 - 虎扑网技术架构如何化解流量高峰
从林书豪到全明星 - 虎扑网技术架构如何化解流量高峰
 
服务器基准测试-叶金荣@CYOU-20121130
服务器基准测试-叶金荣@CYOU-20121130服务器基准测试-叶金荣@CYOU-20121130
服务器基准测试-叶金荣@CYOU-20121130
 
Monitor is all for ops
Monitor is all for opsMonitor is all for ops
Monitor is all for ops
 
基于Innodb开发的最佳实践
基于Innodb开发的最佳实践基于Innodb开发的最佳实践
基于Innodb开发的最佳实践
 
Avm2虚拟机浅析与as3性能优化(陈士凯)
Avm2虚拟机浅析与as3性能优化(陈士凯)Avm2虚拟机浅析与as3性能优化(陈士凯)
Avm2虚拟机浅析与as3性能优化(陈士凯)
 
[Flash开发者交流][2010.05.30]avm2虚拟机浅析与as3性能优化(陈士凯)
[Flash开发者交流][2010.05.30]avm2虚拟机浅析与as3性能优化(陈士凯)[Flash开发者交流][2010.05.30]avm2虚拟机浅析与as3性能优化(陈士凯)
[Flash开发者交流][2010.05.30]avm2虚拟机浅析与as3性能优化(陈士凯)
 
Linux firewall
Linux firewallLinux firewall
Linux firewall
 
Java线上应用问题排查方法和工具(空望)
Java线上应用问题排查方法和工具(空望)Java线上应用问题排查方法和工具(空望)
Java线上应用问题排查方法和工具(空望)
 
Tcfsh bootcamp day2
 Tcfsh bootcamp day2 Tcfsh bootcamp day2
Tcfsh bootcamp day2
 
全端物聯網探索之旅 - 重點整理版
全端物聯網探索之旅 - 重點整理版全端物聯網探索之旅 - 重點整理版
全端物聯網探索之旅 - 重點整理版
 
Beyond rails server
Beyond rails serverBeyond rails server
Beyond rails server
 
Hadoop+spark實作
Hadoop+spark實作Hadoop+spark實作
Hadoop+spark實作
 
Puppet安装总结
Puppet安装总结Puppet安装总结
Puppet安装总结
 
Mysql proxy+mysql-mmm
Mysql proxy+mysql-mmmMysql proxy+mysql-mmm
Mysql proxy+mysql-mmm
 
Module 08 防火牆
Module 08 防火牆Module 08 防火牆
Module 08 防火牆
 
Lvs在大规模网络环境下的应用pukong
Lvs在大规模网络环境下的应用pukongLvs在大规模网络环境下的应用pukong
Lvs在大规模网络环境下的应用pukong
 
Python 于 webgame 的应用
Python 于 webgame 的应用Python 于 webgame 的应用
Python 于 webgame 的应用
 

探索 ISTIO 新型 DATA PLANE 架構 AMBIENT MESH - GOLANG TAIWAN GATHERING #77 X CNTUG

  • 1. GOLANG TAIWAN GATHERING #77 X CNTUG 探索 ISTIO 新型 DATA PLANE 架構 AMBIENT MESH 演講者:耿映翔 演講日期:2023/12/14 演講地點:天瓏書局
  • 2. Service Mesh OUTLINE 自我介紹 動機 Ambient Mesh 運作原理 結論 Ambient Mesh
  • 3. 耿映翔 (阿皮) 主要以 Golang、Vuejs 作為主力開發工具 目前就讀於 彰師大 數科所 (快畢業ㄌ) go-zero, ants-pool Contributor Email: zxc752166@gmail.com 自我介紹
  • 4. 動機 • Golang 微服務 • 需要設定 Platform 層的瑣碎功能 • The more microservices we have, the more difficult it is for developers to configure 參考資料:[1]、[2]
  • 6. Kubernetes and Istio • Golang 微服務 • Service Mesh Implement Functions of Communication in Infra • Developers focus on Business logic +Kubernetes +Istio Service Mesh
  • 7.
  • 8. SERVICE MESH? AMBIENT MESH? Service Mesh: • A infrastructure layer for handling service-to-service communication. • It’s responsible for the reliable delivery of requests through the complex topology of services that comprise a modern, cloud native application. Ambient Mesh: • The new architectural alternative that does not rely on sidecars for a service mesh. • Enables customers to reduce costs up to 90% while simplifying operations and improving performance for their applications. 參考資料:[3]、[4]
  • 9. ISTIO SERVICE MESH • Control Plane ⚬ Pilot:管理 Proxy 路由規則配置 ⚬ Citadel:憑證授權單位 (CA) ⚬ Galley: 配置驗證、提取、處理 • Data Plane ⚬ Sidecar:使用 Envoy (c++ based) 作為 Proxy,攔截 Pod Inbound / Outbound 流量 參考資料:[5]
  • 10. SIDECAR PROXY • Init Container 會使用 IPtables 配置來 kernel 網路規則 • kernel space 與 user space 反覆切換 (同一節點內,至少3次) Init Container Init Container 參考資料:[6]
  • 11. Security Observability Traffic Management #mTLS BENEFITS OF SERVICE MESH #Authorization #Metrics #Distributed Traces #Access Logs #Service Discovery #Retry #Rate Limiting #Timeout #Fault Injection #Circuit Breaker #Diverse Deployment Policies #Load Balancing • Blue Green Deployment • Canary Deployment • A/B Testing
  • 12. Security #mTLS BENEFITS OF SERVICE MESH #Authorization
  • 13. Observability BENEFITS OF SERVICE MESH #Metrics #Distributed Traces #Access Logs 參考資料:[7]
  • 14. Observability BENEFITS OF SERVICE MESH #Metrics #Distributed Traces #Access Logs 參考資料:[8]
  • 15. BENEFITS OF SERVICE MESH Traffic Management #Service Discovery #Retry #Rate Limiting #Timeout #Fault Injection #Circuit Breaker #Diverse Deployment Policies #Load Balancing
  • 16. CHALLENGES OF SERVICE MESH • Sidecar Proxy 無法完全被 Controller Manager (Kubernetes) 的生命週期所控制 ⚬ solution: readiness probe or liveness probe 參考資料:[9]、[10]、[11]、[12]
  • 17. CHALLENGES OF SERVICE MESH • Job 會等待所有容器停止才會銷毀 • Job 資源在執行時,如果被注入 Sidecar,會 導致無法被完整的銷毀,持續占用資源
  • 18. CHALLENGES OF SERVICE MESH • Sidecar 版本升級,要重新部署微服務,可能導致服務不可用
  • 19. CHALLENGES OF SERVICE MESH • 對於 non-HTTP 請求支援非常有限,可能還需要 Aeraki([Air-rah-ki]) Mesh 支援 • 每個 Pod 都會有一個 Sidecar Proxy,一旦 Pod 越多,占用資源也越高
  • 20. ISTIO AMBIENT MESH ● Sidecar-less 的 data plane 部署模型 ● 將 Sidecar Proxy 以 L4 和 L7 的功能進行 分割,並獨立部署 ○ ztunnel (DaemonSet) ○ waypoint proxy (Gateway) ● 使用 HBONE 協議對流量進行封裝 參考資料:[6]、[13]、[14]
  • 21. L4 & L7 PROXY
  • 22. BENEFITS OF AMBIENT MESH • 保留原本 Service Mesh 所提供的功能 • 改善注入 Sidecar,生命週期無法控制的問題 • 使用 HBONE 建立 tunnel 對流量進行簡易封 裝,不會有流量中斷問題 • Proxy 獨立部署,服務與 Proxy 不互相影響 • Proxy 數量減少,降低 Sidecar 部署的成本
  • 24. Ztunnel Packet Flow 服務彼此不在同節點上 服務彼此在同一個節點上
  • 25. Ztunnel + Waypoint Packet Flow • Waypoint Proxy 可以根據 Namespace 或是 ServiceAccount 來進行部署
  • 27. Ztunnel Configuration $ kubectl exec -n istio-system ztunnel-bdqms -c istio-proxy -- curl "127.0.0.1:15000/config_dump?include_eds" "by_addr": { "/10.244.2.5": { "workloadIps": [ "10.244.2.5" ], "waypoint": { "destination": "/10.96.183.171", "port": 15008 }, "protocol": "TCP", "uid": "Kubernetes//Pod/default/httpbin-86869bccff-8v829", "name": "httpbin-86869bccff-8v829", "namespace": "default", "trustDomain": "cluster.local", "serviceAccount": "httpbin", "workloadName": "httpbin", "workloadType": "deployment", "canonicalName": "httpbin", "canonicalRevision": "v1", "node": "ambient-worker2", "status": "Healthy", "clusterId": "Kubernetes" }, // ... } 註:XDS 是用於動態配置 Proxy 的傳輸協議
  • 28. Environment Setup $ kind create cluster --config ./deployment/kind-cluster.yaml --name ambient $ k get node -o wide NAME STATUS ROLES AGE VERSION INTERNAL-IP … ambient-control-plane Ready control-plane 4m14s v1.27.3 172.18.0.3 … ambient-worker Ready <none> 3m49s v1.27.3 172.18.0.4 … ambient-worker2 Ready <none> 3m49s v1.27.3 172.18.0.2 … $ k apply -f ./istio-1.19.0/samples/sleep/sleep.yaml k apply -f ./istio-1.19.0/samples/httpbin/httpbin.yaml serviceaccount/sleep created service/sleep created deployment.apps/sleep created serviceaccount/httpbin created service/httpbin created deployment.apps/httpbin created $ istioctl install --set profile=ambient -y
  • 29. Istio CNI 元件 (CNI Network Plugin) • 以 DaemonSet 佈署於各節點 • 監聽節點和 Pod 變化 • 節點:建立 IPSet 和網路介面,設定 IPTables 和路由規則 • ztunnel Pod:設定 IPTables 和路由規則 • 轉發方式: ⚬ iptables + Geneve tunnel (default) ⚬ ebpf 參考資料:[6]
  • 30. 1. 建立 IPSet ● 紀錄當前 Node 上 Pods 的 IP Address ● Istio-CNI 根據異動,自動進行更新 ● 用途:當封包的 srcIP 命中此集合,將會被標記 metadata (0x100/0x100)。 $ docker exec ambient-worker ipset list Name: ztunnel-pods-ips Type: hash:ip Revision: 0 Header: family inet hashsize 1024 maxelem 65536 Size in memory: 296 References: 1 Number of entries: 1 Members: 10.244.1.7 ambient-worker 的 Pod IP Address $ k get pod -ocustom-columns=NAME:.metadata.name,IP:.status.podIP,NODE:.spec.nodeN ame|grep ambient-worker httpbin-86869bccff-8v829 10.244.2.5 ambient-worker2 sleep-9454cc476-w74cd 10.244.1.7 ambient-worker
  • 31. 2. 建立 Network Interface (Node) $ docker exec ambient-worker ip addr|grep istioin 5: istioin: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1450 qdisc noqueue state UNKNOWN group default inet 192.168.126.1/30 brd 192.168.126.3 scope global istioin $ docker exec ambient-worker ip addr|grep istioout 6: istioout: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1450 qdisc noqueue state UNKNOWN group default inet 192.168.127.1/30 brd 192.168.127.3 scope global istioou • 使用 ptp (point to point) 模式連接 • 添加 istioin 網路介面,IP: 192.168.126.1 • 添加 istioout 網路介面,IP: 192.168.127.1
  • 32. 2. 建立 Network Interface (Pod) $ k -n istio-system exec ztunnel-cmq4f -- ip addr|grep pistioin 3: pistioin: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1450 qdisc noqueue state UNKNOWN group default inet 192.168.126.2/30 brd 192.168.126.3 scope global pistioin $ k -n istio-system exec ztunnel-cmq4f -- ip addr|grep pistioout 4: pistioout: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1450 qdisc noqueue state UNKNOWN group default inet 192.168.127.2/30 brd 192.168.127.3 scope global pistioout • 添加 pistioin 網路介面,IP: 192.168.126.2 • 添加 pistioout 網路介面,IP: 192.168.127.2
  • 33. 2. 建立 Network Interface $ docker exec ambient-worker ip -d link show istioout 9: istioout: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1450 qdisc noqueue state UNKNOWN mode DEFAULT group default link/ether ae:b7:c1:b2:00:4d brd ff:ff:ff:ff:ff:ff promiscuity 0 minmtu 68 maxmtu 65485 geneve id 1001 remote 10.244.1.6 ttl auto dstport 6081 noudpcsum udp6zerocsumrx addrgenmode eui64 numtxqueues 1 numrxqueues 1 gso_max_size 65536 gso_max_segs 65535 $ k -n istio-system exec ztunnel-cmq4f -- ip -d link show pistioout 4: pistioout: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1450 qdisc noqueue state UNKNOWN mode DEFAULT group default link/ether 5e:d6:87:52:61:97 brd ff:ff:ff:ff:ff:ff promiscuity 0 minmtu 68 maxmtu 65485 geneve id 1001 remote 10.244.1.1 ttl auto dstport 6081 noudpcsum udp6zerocsumrx addrgenmode eui64 numtxqueues 1 numrxqueues 1 gso_max_size 65536 gso_max_segs 65535 • istioout 和 istioin 所接收的封包,將會經由 Geneve Tunnel 被傳入 ztunnel Pod 之中 ,也就是 10.244.1.6
  • 34. 3. 設定 Network Interface ● 將 rp_filter 設定為 0,關閉反向路徑過濾 • 1: 嚴格模式,反向路徑若不是同一個網路介面,直接丟棄封包 • 2: 寬鬆模式,反向路徑的封包如果不可到達 (任意介面),就會被丟棄 ● 將 accept_local 設定為 1 • 接受非 loopback 介面傳遞的封包 (srcIP 是 local) accept_local – BOOLEAN Accept packets with local source addresses. In combination with suitable routing, this can be used to direct packets between two local interfaces over the wire and have them accepted properly. default FALSE
  • 35. 4. 設定 IPTables、路由規則 ● 更改 IPTables 上的 NAT 和 MANGLE 表 • NAT:用於更改 srcIP 和 dstIP • MANGLE:用於標記 metadata $ docker exec ambient-worker ip rule 0: from all lookup local 100: from all fwmark 0x200/0x200 goto 32766 101: from all fwmark 0x100/0x100 lookup 101 102: from all fwmark 0x40/0x40 lookup 102 103: from all lookup 100 32766: from all lookup main 32767: from all lookup default $ docker exec ambient-worker ip route show table 101 default via 192.168.127.2 dev istioout 10.244.1.6 dev veth6f1f20dc scope link
  • 37.
  • 39. 1. Sleep NS -> Node NS (Mangle) $ docker exec ambient-worker iptables-save --- mangle — # 原本正在執行的 PREROUTING chain 跳至 ztunnel-PREROUTING chain -A PREROUTING -j ztunnel-PREROUTING # ztunnel-PREROUTING chain 規則 # … -A ztunnel-PREROUTING -m mark --mark 0x200/0x200 -j RETURN -A ztunnel-PREROUTING -p tcp -m set --match-set ztunnel-pods-ips src -j MARK --set-xmark 0x100/0x100 ● 原本 PREROUTING chain 跳至 ztunnel-PREROUTING chain ● 遇到 tcp 的請求,查找 ztunnel-pods-ips 配對 srcIP,有配對成功就標記 0x100/0x100
  • 40. 1. Sleep NS -> Node NS (NAT) $ docker exec ambient-worker iptables-save --- nat — -A PREROUTING -j ztunnel-PREROUTING # 將 ClusterIP dnat 成 PodIP -A PREROUTING -m comment --comment "kubernetes service portals" -j KUBE-SERVICES # 在 ztunnel-PREROUTING chain ACCEPT,所以不會進入 KUBE-SERVICES chain -A ztunnel-PREROUTING -m mark --mark 0x100/0x100 -j ACCEPT ● 原本 PREROUTING chain 跳至 ztunnel-PREROUTING chain ● 讓帶有 0x100/0x100 標記的封包直接通過,前往路由轉發
  • 41. 2. Node NS (NAT) -> Ztunnel NS # 查看路由規則 $ docker exec ambient-worker ip rule 0: from all lookup local 100: from all fwmark 0x200/0x200 goto 32766 101: from all fwmark 0x100/0x100 lookup 101 102: from all fwmark 0x40/0x40 lookup 102 103: from all lookup 100 32766: from all lookup main 32767: from all lookup default ● 路由規則內會命中 fwmark 0x100/0x100 的標記 ● 將封包由 istioout 網路介面進行傳送至 192.168.127.2 的 pistioout 網路介面 # 根據 fwmark 0x100/0x100,查找 table 101 $ docker exec ambient-worker ip route show table 101 default via 192.168.127.2 dev istioout 10.244.1.6 dev veth6f1f20dc scope link
  • 42. 3. Ztunnel NS -> Other Node # 獲取 ztunnel Pod 內的 iptables 規則 $ k -n istio-system exec ztunnel-cmq4f -- iptables-save --- mangle --- # … # 使用 TPORXY 作為轉發,並標記 port, ip, tproxy-mark,用做後 續路由規則中使用 -A PREROUTING -i pistioout -p tcp -j TPROXY --on-port 15001 --on-ip 127.0.0.1 --tproxy-mark 0x400/0xfff # 獲取 ztunnel Pod 內的路由規則 $ k -n istio-system exec ztunnel-cmq4f -- ip rule 0: from all lookup local 20000: from all fwmark 0x400/0xfff lookup 100 20003: from all fwmark 0x4d3/0xfff lookup 100 32766: from all lookup main 32767: from all lookup default $ k -n istio-system exec ztunnel-bbplk -- ip route show table 100 local default dev lo scope host ● 使用 Transparent Proxy 重新導向 127.0.0.1:15001,保留原本的 dstIP ● 將封包由 loopback 網路介面傳送到 ztunnel 的 Process
  • 43. 3. Ztunnel NS -> Other Node
  • 44. 3. Ztunnel NS -> Other Node
  • 45.
  • 46.
  • 47. 1. Node NS -> Ztunnel NS $ docker exec ambient-worker2 ip rule 0: from all lookup local 100: from all fwmark 0x200/0x200 goto 32766 101: from all fwmark 0x100/0x100 lookup 101 102: from all fwmark 0x40/0x40 lookup 102 103: from all lookup 100 32766: from all lookup main 32767: from all lookup default ● 入站流量不會命中 ztunnel-pods-ips,所以直接進入路由轉發 ● 將封包由 istioin 網路介面進行傳送至 192.168.126.2 的 pistioin 網路介面 $ docker exec ambient-worker2 ip route show table 100 10.244.2.5 via 192.168.126.2 dev istioin src 10.244.2.1 10.244.2.10 dev veth6cc9a213 scope link
  • 48. 2. Ztunnel NS # 獲取 ztunnel Pod 內的 iptables 規則 $ k -n istio-system exec ztunnel-bbplk -- iptables-save --- mangle --- # 使用 TPORXY 作為轉發,並標記 port, ip, tproxy-mark,用做後續路 由規則中使用 -A PREROUTING -i pistioin -p tcp -m tcp --dport 15008 -j TPROXY --on-port 15008 --on-ip 127.0.0.1 --tproxy-mark 0x400/0xfff -A PREROUTING -i pistioin -p tcp -j TPROXY --on-port 15006 --on-ip 127.0.0.1 --tproxy-mark 0x400/0xfff # 獲取 ztunnel Pod 內的路由規則 $ k -n istio-system exec ztunnel-bbplk -- ip rule 0: from all lookup local 20000: from all fwmark 0x400/0xfff lookup 100 20003: from all fwmark 0x4d3/0xfff lookup 100 32766: from all lookup main 32767: from all lookup default $ k -n istio-system exec ztunnel-bbplk -- ip route show table 100 local default dev lo scope host ● 判斷目標端口是否為 15008,是代表有 TLS,否則是明文,一樣使用 Transparent Proxy ● 將封包由 loopback 網路介面傳送到 ztunnel 的 Process
  • 49. 3. Ztunnel NS -> Httpbin NS
  • 50. 3. Ztunnel NS -> Httpbin NS
  • 51.
  • 52. CONCLUSION ● Ambient Mesh 特點 • Proxy 獨立部署,免除生命週期不可控問題和 istio 升級問題 • 使用 HBONE 協議,避免不支援協議的流量中斷問題 • Proxy 可以按需擴充,降低運算資源的成本 ● Ambient Mesh 攔截方式 • 透過 IPSet、IPTables、路由規則轉發至 istioin/istioout 網路介面 • 使用 Geneve Tunnel 讓節點與 zutnnel Pod 之間的網路介面進行連接 • 使用 TProxy 傳輸 Pod 到 ztunnel Process 之間的流量 • 使用 HBONE 協議建立 Tunnel 安全傳輸 TCP 流量
  • 53. REFERENCES [1] 微服務實踐。https://hackmd.io/@maxcian/microservices-in-practices [2] 如何透過 Go-kit 快速搭建微服務架構應用程式實戰 | GopherCon TW 2020。https://www.youtube.com/watch?v=tcfVgusbqy0。 [3] Service Mesh。https://www.techtarget.com/searchitoperations/definition/service-mesh。 [4] Ambient Mesh。https://www.solo.io/products/ambient-mesh/。 [5] Istio Architecture。https://istio.io/latest/docs/ops/deployment/architecture/。 [6] 如何构建 Sidecarless 模式的高性能服务网格。https://www.cnblogs.com/alisystemsoftware/p/17654717.html。 [7] Grafana vs Prometheus。https://blog.knoldus.com/grafana-vs-prometheus/。 [8] Jaeger Tracing: A Friendly Guide for Beginners。 https://medium.com/jaegertracing/jaeger-tracing-a-friendly-guide-for-beginners-7b53a4a568ca。 [9] Istio’s networking: An in-depth look at traffic and architecture。 https://www.solo.io/blog/istios-networking-in-depth/。 [10] Istio Ambient Explained。https://www.oreilly.com/library/view/istio-ambient-explained/9781098142698/ch01.html。 [11] Istio Sidecar注入原理。https://haoyunlaile.github.io/2020/istio/istio-sidecar-injector/。 [12] Kubernetes 特性调研: Sidecar Containers。https://zhuanlan.zhihu.com/p/369371749。 [13] Introducing Ambient Mesh。https://istio.io/latest/blog/2022/introducing-ambient-mesh/。 [14] Istio Ambient 模式流量管理实现机制详解(一)。https://www.zhaohuabing.com/post/2022-09-11-ambient-deep-dive-1/。 [15] SDN x Cloud Native Meetup - Webinar 邱牛上菜 #1 IPTABLES I。https://youtu.be/y4e_B6PdX8A?si=POt8bI8MMIn39KMi。 [16] 全网最细-深度解析 Istio Ambient Mesh 流量路径。https://www.cnblogs.com/alisystemsoftware/p/17760960.html。