Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
用 Go 開發自己的 Kubernetes Device Plugins
Search
Kyle Bai
April 25, 2018
Technology
0
190
用 Go 開發自己的 Kubernetes Device Plugins
本議程將教大家如何用 Go 撰寫簡單 Kubernetes Device Plugins,讓你的 Kubernetes 叢集可以提供各種硬體裝置的使用。
Kyle Bai
April 25, 2018
Tweet
Share
More Decks by Kyle Bai
See All by Kyle Bai
讓 Jenkins 老爺爺掌舵帶領開發者航向美好新世界
kairen
1
190
AWS Startup 2020 - AMIS
kairen
0
60
學習 Kubernetes 不是為了成為 YAML Engineer
kairen
0
290
How to make your container:Kubernetes is a bit more secure
kairen
0
160
Vishwakarma: Terraform modules for deploying EKS and Self-hosting Kubernetes(AWS))
kairen
0
79
Vishwakarma: Terraform modules for deploying EKS and Self-hosting Kubernetes
kairen
0
82
Chatbot as a Service on Container(Kubernetes)
kairen
0
890
IT IRONMAN 2020
kairen
0
69
Advanced Kubernetes For UMC
kairen
0
140
Other Decks in Technology
See All in Technology
LangChain Interrupt & LangChain Ambassadors meetingレポート
os1ma
2
210
CI/CD/IaC 久々に0から環境を作ったらこうなりました
kaz29
1
200
本が全く読めなかった過去の自分へ
genshun9
0
670
怖くない!はじめてのClaude Code
shinya337
0
280
Beyond Kaniko: Navigating Unprivileged Container Image Creation
f30
0
100
開発生産性を組織全体の「生産性」へ! 部門間連携の壁を越える実践的ステップ
sudo5in5k
0
300
CursorによるPMO業務の代替 / Automating PMO Tasks with Cursor
motoyoshi_kakaku
2
730
Fabric + Databricks 2025.6 の最新情報ピックアップ
ryomaru0825
1
150
Tokyo_reInforce_2025_recap_iam_access_analyzer
hiashisan
0
130
ドメイン特化なCLIPモデルとデータセットの紹介
tattaka
1
350
Connect 100+を支える技術
kanyamaguc
0
140
OpenHands🤲にContributeしてみた
kotauchisunsun
1
490
Featured
See All Featured
Measuring & Analyzing Core Web Vitals
bluesmoon
7
500
The Power of CSS Pseudo Elements
geoffreycrofte
77
5.8k
Practical Orchestrator
shlominoach
188
11k
A designer walks into a library…
pauljervisheath
207
24k
Making the Leap to Tech Lead
cromwellryan
134
9.4k
Building Better People: How to give real-time feedback that sticks.
wjessup
367
19k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
507
140k
StorybookのUI Testing Handbookを読んだ
zakiyama
30
5.8k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
248
1.3M
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
8
800
Learning to Love Humans: Emotional Interface Design
aarron
273
40k
Side Projects
sachag
455
42k
Transcript
⽤用 Go 開發⾃自⼰己的 Kubernetes Device Plugins Golang Taiwan
About Me ⽩白凱仁(Kyle Bai) • Interested in emerging technologies. •
COSCUP, Kubernetes Day and OpenStack Day Speaker • OpenStack and Kubernetes Projects Contributor(100+ PR) • Certified Kubernetes Administrator • HR(Hunter Rank) 300+ @kairen(
[email protected]
) https://kairen.github.io/
Why device plugins? • Out of Tree,Kubernetes ⼀一直以來來是專注⾃自⾝身核⼼心 與通⽤用擴展功能(Customization /
extensibility)。ex: CNI、CSI、CRI 等等。 • Out of Tree 讓開發迭代更更佳靈活。 • 開放式的軟體架構與標準化對社區推動有很多幫助。
• 將不同 Device (如 GPU、FPGA 等)交給領域專家或公司來來開發提供。 • 傳統 alpha.kubernetes.io/nvidia-gpu 將在
v1.11 版本移除(#61498)。 Device Plugin RDMA
Device Plugins Device Plugins 是 Kubernetes v1.8 加入的特性,⽬目標是以通⽤用介⾯面提供第三⽅方設備廠商開發插件化⽅方式 將裝置(如 GPU)資源串串接⾄至
Kubernetes 上,並且提供容器 Extended Resources。 ⽬目前關注度⾼高的 Device plugins: • NVIDIA device plugin for Kubernetes • AMD device plugin for Kubernetes • Solarflare Device Plugin * Feature state: Kubernetes v1.10 v1beta1
Device Plugin Architecture Device plugin 主要實作為以下: • Registration • ListAndWatch
• Allocate: • PreStartContainer
Device Plugin Interface
Registration 當 Kubernetes 啟動 DevicePlugins Feature Gate 時,Kubelet 會曝露⼀一個 Register
gRPC 介⾯面,⽽而 Device Plugins 需要透過該介⾯面完成 Device 註冊並提供 Unix socket 作為溝通。
Registration Interface
ListAndWatch 監聽對應的硬體裝置狀狀態變更更或者 Disappear 事件,並提供硬體裝置列列表給 Kubelet,在硬體裝置發⽣生變 化時再次傳送。
監聽對應 Devices 的狀狀態或者 Disappear 事件,回傳 ListAndWatchResponse 給 kubelet, ListAndWatchResponse 即
Device 列列表。 ListAndWatch Interface
Allocate 當建立容器時,Kubelet 呼叫 Device plugin 的 Allocate 函式來來執⾏行行硬體設備的特定指令(如 GPU cleanup
or initialization 等等),並告知 Kubelet 如何使容器能夠使⽤用該硬體裝置(如告知 docker 在建立容器時使⽤用 分配的硬體裝置)。 Allocate 允許 Device Plugin在 Device requested 的裝置上執⾏行行特定的操作。
None
PreStartContainer • 預計將在每個容器啟動之前呼叫該 API,如果再註冊階段中有標⽰示啟⽤用的話。 • 允許 kubelet 將重新初始化的 devices 傳給容器。
• 允許 Device Plugin在 Device requested 的裝置上執⾏行行特定的操作。(同 Allocate)
Device Plugins Workflow and Phase Device Plugins 的執⾏行行流程如下: 1. 初始化:Device
Plugins 啟動時,進⾏行行⼀一些插件特定初始化⼯工作確保對應 Devices 處於 Ready 狀狀態。 如 NVIDIA GPU 就是載入 NVML Library。 2. 啟動 gPRC:透過 /var/lib/kubelet/device-plugins/*.sock 對外曝露 gRPC 服務。(不同版本 API 會有 不同 gRPC API) 3. 註冊:Device Plugin 透過 /var/lib/kubelet/device-plugins/kubelet.sock 向 kubelet 進⾏行行註冊。 4. Serve Device Plugin:當註冊完成就會進入 Serving 模式,並提供 ListAndWatch、Allocate 等 gRPC 介⾯面呼叫服務。
None
HealthCheck and Failure Recovery 由於 kubelet 重新啟動時,都會將 /var/lib/kubelet/device-plugins/ 底下所有 unix
socket 檔案刪除,因 此 Device Plugin 需要負責監測⾃自⼰己的 socket 被刪除,並重新註冊來來產⽣生新的 socket 檔案。 • 透過 fsnotify.Watcher 監控 /var/lib/kubelet/device-plugins/ ⽬目錄。 • 如果 fsnotify.Watcher 的 Events channel 收到 Create kubelet.socket 事件的話,就觸發 Device plugins restart。 • 如果 fsnotify.Watcher 的 Events channel 收到 Device plugin socket 被刪除事件,⼀一樣觸發 Device plugins restart。(這種情狀狀是避免 device plugin socket 被誤刪)
Extended Resources • Device Plugin 透過 Extended Resources 來來 expose
主機上的資源,Kubernetes 內建的 Resources 都會 是以 kubernetes.io domain 為開頭,因此 Extended Resource 不允許使⽤用。 • Device Plugin 的 Extended Resource 屬於 Node-level。 • Extended Resource 只能是整數,如 2, 100m, 2Ki。 • 容器的 resource filed 只能設置為 Guaranteed QoS,簡單說要⿇麻只設定 limits,要⿇麻 request 與 limits ⼀一 樣。 • 被分配的 Device 只能被單⼀一容器佔⽤用。
Let’s go to implement!!
Example Architecture
None
Project Structure • Go files: • main.go: Device Plugin 初始化與啟動,⼀一切從
main func 開始。 • sata.go: 簡單⽤用 lsblk 取得 Host SATA devices(/dev/sd[x])。 • server.go: Device Plugin gRPC 介⾯面實作。 • watcher.go: FS 與 OS watcher new func。 • artifacts: Kubernetes deploy files. • Dockerfile: Build device plugin image. • Vagrantfile: Setup Kubernetes cluster.
Demo https://github.com/kairen/simple-device-plugin
Thank you for your attention!!