狠狠撸

狠狠撸Share a Scribd company logo
HungWei Chiu 09/01/2022 LINE O
ffi
ce
Kubernetes 網路除錯?苦談
Who
? 矽??耕?筆記
? CNTUG 志?
? 個?部落格
? https://hwchiu.com
網路除錯之必要性與複雜性
? Kubernetes 主要三??向
? 運算/網路/儲存
? 運算
? 基本上都基於容器為主,?部分使?者都可以藉由 Docker 等?式本地熟悉與學習,所以熟悉度最?
? 儲存
? 複雜但非必要,預設環境下不透過外部儲存也是可以正常運作
? 網路
? 複雜且必要,但是?部分的操作都被 Kubernetes 給抽象處理
? 不需要知道細節也可以運作,這是?個雙?刃
Kubernetes 的網路流量
? 以叢集為基點去觀看封包流向,?抵上可以分成東?向與南北向
? 南北向
? 流量進出叢集
? 東?向
? 流量於叢集中竄流
Kubernetes 的網路流量
? 南北向
? 外部服務如何存取叢集內的服務
? Ingress, API-Gateway, Load-Balancer 等
? 叢集內服務如何存取外部網路
? NAT(Network Address Translation)
Kubernetes 的網路流量
? 東?向
? 存取?向
? Pod to Service
? Pod to Pod
? 存取範圍
? 同節點
? 跨節點
Kubernetes 的網路流量
Kubernetes 南北向簡易畫法
Kubernetes 南北向其他架構
Debug Your Kubernetes Network
Debug Your Kubernetes Network
Debug Your Kubernetes Network
Kubernetes 東?向簡易畫法
Debug Your Kubernetes Network
Kubernetes 的網路流量
? 沒有?個萬解的網路架構
? 所有網路問題都要根據?標環境攤開來講
? 前述所有的圖都只是非常粗略不講細節的流向圖
? 架構為主,不探討實作
? 實務上除錯與維運則需要把實作給考慮進來
Kubernetes 的網路元件
? 基本上可以分成四類
? 底层基础建设
? 內建
? CNI
? 第三?功能
? 這些網路元件互相整合才使得叢集有基本的網路功能
? 只要?個出錯,就會造成網路功能不如預期
Kubernetes 的網路元件
? 底层基础建设
? 雲端使?者
? 就是滿滿的 VPC + Firewall + Routing
? 地端維運?員
? 節點與節點之間的連線,同時基本的 IP 發放
? 中間是否牽扯 Router/Switch,是否跨機櫃等
? 問你家網管
底层基础建设
Kubernetes 的網路元件
? 內建
? Kubernetes Service
? Kube-Proxy
? Iptables/ipvs
? Kubernetes Ingress
? 取決於你?哪?套 Ingress,不同套的實作細節不同
? CoreDNS
? HostNetwork (跳脫 CNI,繼承節點網路)
? Network Policy
? 取決於 CNI 設定
Debug Your Kubernetes Network
Kubernetes 的網路元件
? CNI 很深
? Calico -> BGP/IPIP
? Flannel -> VXLAN
? Cilium -> eBPF
? OVS -> OpenFlow
? Cloud-Provider speci
fi
ed
? AWS/Azure
CNI
Kubernetes 的網路元件
? 第三?功能
? Service Mesh
? Cluster Federation
? ...
? 這些功能都必須要建立於 Kubernetes 之上,同時疊加更多更複雜的功能來處理
網路封包
? 基礎功不夠,就只能當 YAML ?程師
Debug Your Kubernetes Network
Kubernetes 的除錯思路
? 網路非常複雜,也是最難除錯的
? 遇到問題第?步都是釐清
? ?向性
? 到底是南北向問題還是東?向問題
? 問題點
? 基礎建設? K8s? CNI? 第三?整合?
Kubernetes 的除錯思路
? 網路問題極度不推薦?嘴除錯
? 推薦做法
? 畫出整個系統架構圖
? 標?出你的網路情境(從誰想要透過何種?式存取誰)
? 將??想像成?個封包,於架構圖上解釋你認為封包會怎麼流動
? 這個步驟沒有辦法就代表你對於整體網路還是有不熟的地?
? 以上述過程的流動?式為基準開始除錯,透過測試的?式來逐漸縮?範圍
Kubernetes 的除錯思路
Kubernetes 的除錯思路
Kubernetes 的除錯思路
? 假設你聽到有?描述「我的 Pod 不能存取某個 Service 耶?」
? 你聽到會有什麼反應?
? 你期望對?告訴你什麼?
Kubernetes 的除錯思路
? 我通常會反問對?
? 你做過哪些測試?
? 你?前排除過哪些問題點?
? 這也是?個良好的合作?式,不要當無腦伸?牌
? 問問題請同時敘述??做過什麼嘗試,???前認為卡關在哪裡
思路範例
? 「我的 Pod 不能存取某個 Service 耶?」
? 跟 DNS 解析有無問題? 直接使? ClusterIP 試試看
? 跟 Service 轉換是否有關? 直接打 Pod IP 試試看?
? 跟節點是否有關係? 從同節點上的 Pod 打看看?
? 從節點直接打看看?
? 是否有 Network Policy?
思路範例
? 「我的 Pod 不能存取某個 Service 耶?」
? 縮?範圍後如果還是不能釐清問題點,嘗試錄製封包
? 封包流向
? Server 沒收到
? Server 有收到,沒有回
? Server 有收到,也有回,但是 Client 沒有收到
思路範例
? 「我的 Pod 不能存取某個 Service 耶?」
? 錄製的封包是否可以看出問題?
? 可能封包不如預期,被 Kernel 丟掉?
? 封包錄製不到?
? 問題發?於底層架構,請求其他?幫忙
擷取封包
? 當現存?具都沒有辦法幫忙釐清為什麼網路不會通,這時候就可以借助抓取封
包的?式來判斷
? 問題要有辦法重現搭配擷取封包才好處理,否則事情已經發?,錯誤的封包已
經消失這時候其實也沒有辦法擷取分析
? 常?問題有
? 要?什麼?具擷取分析?
? 要如何從茫茫封包中找到?標封包?
什麼?具
? 常??具如 wireshark/tcpdump/tshark
? ?部分?環境不?定有 GUI 可以?,所以純 CLI ?具要優先熟悉
? 有了?具下?個就是誰要去運?這些?具來錄製封包?
? 節點:
? 管理上容易,要安裝?具也相對容易
? Pod 本?:
? 取決於運?容器,不?定有想要的除錯?具
什麼?具 - 解決?式
? 節點: ??安裝
? Pod 本?:
? 可以透過 ksni
ff
這套?具,該套?具可獨立使?也可以掛到 kubectl plugin 使
?
? 透過 kubectl 上傳?個事先編譯好的 tcpdump binary 到?標 Pod,並且將節
果給傳回到執?端
? 執?端如果有 wireshark,會打開變成串流模式
尋找封包
? 假設今天是?個叢集內的東?向請求,該請求封包實際上會經過的落點非常多
? 不同發?點錄製的封包數量完全不?樣
? 完美情況是只要錄製跟?標有關的封包
? 最壞情況下就是錄製??堆封包,然後嘗試從這些封包中找到?標封包
寻找封包(精简图)
尋找封包
? 從節點出發錄製封包往往遇到的第?個問題是,我要監聽哪?個網卡?
? 以 tcpdump 為範例
? -i any -> 監聽所有網卡,資料量最多,過濾最?煩
? -i xxxx -> 可以直接找到?標網卡的話,資料最精準
? CNI 的實作?式不同會使得這個網卡的?式不同
? 有?些 CNI 還會把封包進??次封裝,如 vxlan, ipip 等,這些都會使得你收到的
封包不是你真的想要看到的封包
其他雜錄
? 除了 Kubernetes 內的基本概念外, Linux 本?的概念也要有
? 常??具
? ip/tcpdump
? Conntrack
? 系統有上限,超過就會出現連線問題
? Iptables/ipvs
? 網卡資訊與控制
? Ethtool
? rp_
fi
lter/routing/NAT ...etc
Q&A
Ad

Recommended

Learn O11y from Grafana ecosystem.
Learn O11y from Grafana ecosystem.
HungWei Chiu
?
ArgoCD 的雷 碰過的人就知道 @TSMC IT Community Meetup #4
ArgoCD 的雷 碰過的人就知道 @TSMC IT Community Meetup #4
Johnny Sung
?
[Flutter] 來體驗 bloc 小方塊的神奇魔法 @Devfest 2022
[Flutter] 來體驗 bloc 小方塊的神奇魔法 @Devfest 2022
Johnny Sung
?
Optimizing Kubernetes Resource Requests/Limits for Cost-Efficiency and Latenc...
Optimizing Kubernetes Resource Requests/Limits for Cost-Efficiency and Latenc...
Henning Jacobs
?
Diabetes Mellitus
Diabetes Mellitus
MD Abdul Haleem
?
Power Point Presentation on Artificial Intelligence
Power Point Presentation on Artificial Intelligence
Anushka Ghosh
?
Republic Act No. 11313 Safe Spaces Act (Bawal Bastos Law).pptx
Republic Act No. 11313 Safe Spaces Act (Bawal Bastos Law).pptx
maricelabaya1
?
Hypertension
Hypertension
Ratheeshkrishnakripa
?
Introduction to CNI (Container Network Interface)
Introduction to CNI (Container Network Interface)
HungWei Chiu
?
Getting Started with Kubernetes
Getting Started with Kubernetes
VMware Tanzu
?
An overview of the Kubernetes architecture
An overview of the Kubernetes architecture
Igor Sfiligoi
?
Kubernetes Basics
Kubernetes Basics
Eueung Mulyana
?
Docker and kubernetes
Docker and kubernetes
Dongwon Kim
?
Hands-On Introduction to Kubernetes at LISA17
Hands-On Introduction to Kubernetes at LISA17
Ryan Jarvinen
?
Introduction to kubernetes
Introduction to kubernetes
Gabriel Carro
?
Kubernetes Architecture
Kubernetes Architecture
Knoldus Inc.
?
Kubernetes Architecture | Understanding Kubernetes Components | Kubernetes Tu...
Kubernetes Architecture | Understanding Kubernetes Components | Kubernetes Tu...
Edureka!
?
Kubernetes: An Introduction to the Open Source Container Orchestration Platform
Kubernetes: An Introduction to the Open Source Container Orchestration Platform
Michael O'Sullivan
?
Introduction to kubernetes
Introduction to kubernetes
Raffaele Di Fazio
?
Introduction to kubernetes
Introduction to kubernetes
Michal Cwienczek
?
Learned from KIND
Learned from KIND
HungWei Chiu
?
OpenStack Ironic - Bare Metal-as-a-Service
OpenStack Ironic - Bare Metal-as-a-Service
Ramon Acedo Rodriguez
?
Kubernetes - introduction
Kubernetes - introduction
Sparkbit
?
Kubernetes 101
Kubernetes 101
Crevise Technologies
?
01. Kubernetes-PPT.pptx
01. Kubernetes-PPT.pptx
TamalBanerjee16
?
Container Networking Deep Dive
Container Networking Deep Dive
Open Networking Summit
?
Kubernetes
Kubernetes
erialc_w
?
CyberAgentのインフラについて メディア事業編 #catechchallenge
CyberAgentのインフラについて メディア事業編 #catechchallenge
whywaita
?
企業導入微服務實戰 - updated
企業導入微服務實戰 - updated
Paul Chao
?
廣宣學堂: 企業導入微服務實戰
廣宣學堂: 企業導入微服務實戰
Paul Chao
?

More Related Content

What's hot (20)

Introduction to CNI (Container Network Interface)
Introduction to CNI (Container Network Interface)
HungWei Chiu
?
Getting Started with Kubernetes
Getting Started with Kubernetes
VMware Tanzu
?
An overview of the Kubernetes architecture
An overview of the Kubernetes architecture
Igor Sfiligoi
?
Kubernetes Basics
Kubernetes Basics
Eueung Mulyana
?
Docker and kubernetes
Docker and kubernetes
Dongwon Kim
?
Hands-On Introduction to Kubernetes at LISA17
Hands-On Introduction to Kubernetes at LISA17
Ryan Jarvinen
?
Introduction to kubernetes
Introduction to kubernetes
Gabriel Carro
?
Kubernetes Architecture
Kubernetes Architecture
Knoldus Inc.
?
Kubernetes Architecture | Understanding Kubernetes Components | Kubernetes Tu...
Kubernetes Architecture | Understanding Kubernetes Components | Kubernetes Tu...
Edureka!
?
Kubernetes: An Introduction to the Open Source Container Orchestration Platform
Kubernetes: An Introduction to the Open Source Container Orchestration Platform
Michael O'Sullivan
?
Introduction to kubernetes
Introduction to kubernetes
Raffaele Di Fazio
?
Introduction to kubernetes
Introduction to kubernetes
Michal Cwienczek
?
Learned from KIND
Learned from KIND
HungWei Chiu
?
OpenStack Ironic - Bare Metal-as-a-Service
OpenStack Ironic - Bare Metal-as-a-Service
Ramon Acedo Rodriguez
?
Kubernetes - introduction
Kubernetes - introduction
Sparkbit
?
Kubernetes 101
Kubernetes 101
Crevise Technologies
?
01. Kubernetes-PPT.pptx
01. Kubernetes-PPT.pptx
TamalBanerjee16
?
Container Networking Deep Dive
Container Networking Deep Dive
Open Networking Summit
?
Kubernetes
Kubernetes
erialc_w
?
CyberAgentのインフラについて メディア事業編 #catechchallenge
CyberAgentのインフラについて メディア事業編 #catechchallenge
whywaita
?
Introduction to CNI (Container Network Interface)
Introduction to CNI (Container Network Interface)
HungWei Chiu
?
Getting Started with Kubernetes
Getting Started with Kubernetes
VMware Tanzu
?
An overview of the Kubernetes architecture
An overview of the Kubernetes architecture
Igor Sfiligoi
?
Docker and kubernetes
Docker and kubernetes
Dongwon Kim
?
Hands-On Introduction to Kubernetes at LISA17
Hands-On Introduction to Kubernetes at LISA17
Ryan Jarvinen
?
Introduction to kubernetes
Introduction to kubernetes
Gabriel Carro
?
Kubernetes Architecture
Kubernetes Architecture
Knoldus Inc.
?
Kubernetes Architecture | Understanding Kubernetes Components | Kubernetes Tu...
Kubernetes Architecture | Understanding Kubernetes Components | Kubernetes Tu...
Edureka!
?
Kubernetes: An Introduction to the Open Source Container Orchestration Platform
Kubernetes: An Introduction to the Open Source Container Orchestration Platform
Michael O'Sullivan
?
OpenStack Ironic - Bare Metal-as-a-Service
OpenStack Ironic - Bare Metal-as-a-Service
Ramon Acedo Rodriguez
?
Kubernetes - introduction
Kubernetes - introduction
Sparkbit
?
CyberAgentのインフラについて メディア事業編 #catechchallenge
CyberAgentのインフラについて メディア事業編 #catechchallenge
whywaita
?

Similar to Debug Your Kubernetes Network (20)

企業導入微服務實戰 - updated
企業導入微服務實戰 - updated
Paul Chao
?
廣宣學堂: 企業導入微服務實戰
廣宣學堂: 企業導入微服務實戰
Paul Chao
?
企業導入微服務實戰 - updated
企業導入微服務實戰 - updated
Paul Chao
?
開發人員必須知道的 Kubernetes 核心技術 - Kubernetes Summit 2018
開發人員必須知道的 Kubernetes 核心技術 - Kubernetes Summit 2018
Will Huang
?
如何盡量避免 Throttling 在 K8s 中 (How to reduce throttling in k8s)
如何盡量避免 Throttling 在 K8s 中 (How to reduce throttling in k8s)
Kiwi Lee
?
出了问题不要靠猜
出了问题不要靠猜
LI Daobing
?
Windows Container 101: dotNET, Container, Kubernetes
Windows Container 101: dotNET, Container, Kubernetes
Will Huang
?
Ruby 的快与慢
Ruby 的快与慢
vincent253
?
改善 Angular 開發流程:你所不知道的 Schematics 程式碼產生器
改善 Angular 開發流程:你所不知道的 Schematics 程式碼產生器
Chieh Kai Yang
?
Kvmopt osforce
Kvmopt osforce
meecheng
?
美团技术团队 - KVM性能优化
美团技术团队 - KVM性能优化
美团点评技术团队
?
A brief introduction to Vagrant – 原來 VirtualBox 可以這樣玩
A brief introduction to Vagrant – 原來 VirtualBox 可以這樣玩
Wen-Tien Chang
?
微服務架構 導入經驗分享 吳剛志 - Community Open Camp
微服務架構 導入經驗分享 吳剛志 - Community Open Camp
Andrew Wu
?
主库自动切换 V2.0
主库自动切换 V2.0
jinqing zhu
?
惭测厂蚕尝自动切换设计与实现
惭测厂蚕尝自动切换设计与实现
orczhou
?
1到100000000 - 分布式大型网站的架构设计
1到100000000 - 分布式大型网站的架构设计
RolfZhang
?
从林书豪到全明星 - 虎扑网技术架构如何化解流量高峰
从林书豪到全明星 - 虎扑网技术架构如何化解流量高峰
Scourgen Hong
?
SACC2015 ”互联网+“任重而道远-白金&高春辉
SACC2015 ”互联网+“任重而道远-白金&高春辉
ptcracker
?
Asp.net core v1.0
Asp.net core v1.0
國昭 張
?
Asp.net core v1.0
Asp.net core v1.0
chang kuo-chao
?
企業導入微服務實戰 - updated
企業導入微服務實戰 - updated
Paul Chao
?
廣宣學堂: 企業導入微服務實戰
廣宣學堂: 企業導入微服務實戰
Paul Chao
?
企業導入微服務實戰 - updated
企業導入微服務實戰 - updated
Paul Chao
?
開發人員必須知道的 Kubernetes 核心技術 - Kubernetes Summit 2018
開發人員必須知道的 Kubernetes 核心技術 - Kubernetes Summit 2018
Will Huang
?
如何盡量避免 Throttling 在 K8s 中 (How to reduce throttling in k8s)
如何盡量避免 Throttling 在 K8s 中 (How to reduce throttling in k8s)
Kiwi Lee
?
出了问题不要靠猜
出了问题不要靠猜
LI Daobing
?
Windows Container 101: dotNET, Container, Kubernetes
Windows Container 101: dotNET, Container, Kubernetes
Will Huang
?
Ruby 的快与慢
Ruby 的快与慢
vincent253
?
改善 Angular 開發流程:你所不知道的 Schematics 程式碼產生器
改善 Angular 開發流程:你所不知道的 Schematics 程式碼產生器
Chieh Kai Yang
?
Kvmopt osforce
Kvmopt osforce
meecheng
?
A brief introduction to Vagrant – 原來 VirtualBox 可以這樣玩
A brief introduction to Vagrant – 原來 VirtualBox 可以這樣玩
Wen-Tien Chang
?
微服務架構 導入經驗分享 吳剛志 - Community Open Camp
微服務架構 導入經驗分享 吳剛志 - Community Open Camp
Andrew Wu
?
主库自动切换 V2.0
主库自动切换 V2.0
jinqing zhu
?
惭测厂蚕尝自动切换设计与实现
惭测厂蚕尝自动切换设计与实现
orczhou
?
1到100000000 - 分布式大型网站的架构设计
1到100000000 - 分布式大型网站的架构设计
RolfZhang
?
从林书豪到全明星 - 虎扑网技术架构如何化解流量高峰
从林书豪到全明星 - 虎扑网技术架构如何化解流量高峰
Scourgen Hong
?
SACC2015 ”互联网+“任重而道远-白金&高春辉
SACC2015 ”互联网+“任重而道远-白金&高春辉
ptcracker
?
Asp.net core v1.0
Asp.net core v1.0
國昭 張
?
Ad

More from HungWei Chiu (20)

以 eBPF 構建一個更為堅韌的 Kubernetes 叢集
以 eBPF 構建一個更為堅韌的 Kubernetes 叢集
HungWei Chiu
?
Learning how AWS implement AWS VPC CNI
Learning how AWS implement AWS VPC CNI
HungWei Chiu
?
Jenkins & IaC
Jenkins & IaC
HungWei Chiu
?
The relationship between Docker, Kubernetes and CRI
The relationship between Docker, Kubernetes and CRI
HungWei Chiu
?
Life
Life
HungWei Chiu
?
Introduction to CRI and OCI
Introduction to CRI and OCI
HungWei Chiu
?
IP Virtual Server(IPVS) 101
IP Virtual Server(IPVS) 101
HungWei Chiu
?
Opentracing 101
Opentracing 101
HungWei Chiu
?
iptables and Kubernetes
iptables and Kubernetes
HungWei Chiu
?
IPTABLES Introduction
IPTABLES Introduction
HungWei Chiu
?
Open vSwitch Introduction
Open vSwitch Introduction
HungWei Chiu
?
Load Balancing 101
Load Balancing 101
HungWei Chiu
?
How Networking works with Data Science
How Networking works with Data Science
HungWei Chiu
?
Introduction to CircleCI
Introduction to CircleCI
HungWei Chiu
?
Head First to Container&Kubernetes
Head First to Container&Kubernetes
HungWei Chiu
?
Kubernetes 1001
Kubernetes 1001
HungWei Chiu
?
Application-Based Routing
Application-Based Routing
HungWei Chiu
?
Build Your Own CaaS (Container as a Service)
Build Your Own CaaS (Container as a Service)
HungWei Chiu
?
Control Your Network ASICs, What Benefits switchdev Can Bring Us
Control Your Network ASICs, What Benefits switchdev Can Bring Us
HungWei Chiu
?
Automatically Renew Certificated In Your Kubernetes Cluster
Automatically Renew Certificated In Your Kubernetes Cluster
HungWei Chiu
?
以 eBPF 構建一個更為堅韌的 Kubernetes 叢集
以 eBPF 構建一個更為堅韌的 Kubernetes 叢集
HungWei Chiu
?
Learning how AWS implement AWS VPC CNI
Learning how AWS implement AWS VPC CNI
HungWei Chiu
?
The relationship between Docker, Kubernetes and CRI
The relationship between Docker, Kubernetes and CRI
HungWei Chiu
?
Introduction to CRI and OCI
Introduction to CRI and OCI
HungWei Chiu
?
IP Virtual Server(IPVS) 101
IP Virtual Server(IPVS) 101
HungWei Chiu
?
iptables and Kubernetes
iptables and Kubernetes
HungWei Chiu
?
IPTABLES Introduction
IPTABLES Introduction
HungWei Chiu
?
Open vSwitch Introduction
Open vSwitch Introduction
HungWei Chiu
?
How Networking works with Data Science
How Networking works with Data Science
HungWei Chiu
?
Introduction to CircleCI
Introduction to CircleCI
HungWei Chiu
?
Head First to Container&Kubernetes
Head First to Container&Kubernetes
HungWei Chiu
?
Application-Based Routing
Application-Based Routing
HungWei Chiu
?
Build Your Own CaaS (Container as a Service)
Build Your Own CaaS (Container as a Service)
HungWei Chiu
?
Control Your Network ASICs, What Benefits switchdev Can Bring Us
Control Your Network ASICs, What Benefits switchdev Can Bring Us
HungWei Chiu
?
Automatically Renew Certificated In Your Kubernetes Cluster
Automatically Renew Certificated In Your Kubernetes Cluster
HungWei Chiu
?
Ad

Debug Your Kubernetes Network