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
260
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
用 Go 開發自己的 Kubernetes Device Plugins
本議程將教大家如何用 Go 撰寫簡單 Kubernetes Device Plugins,讓你的 Kubernetes 叢集可以提供各種硬體裝置的使用。
Kyle Bai
April 25, 2018
More Decks by Kyle Bai
See All by Kyle Bai
讓 Jenkins 老爺爺掌舵帶領開發者航向美好新世界
kairen
1
260
AWS Startup 2020 - AMIS
kairen
0
91
學習 Kubernetes 不是為了成為 YAML Engineer
kairen
0
360
How to make your container:Kubernetes is a bit more secure
kairen
0
220
Vishwakarma: Terraform modules for deploying EKS and Self-hosting Kubernetes(AWS))
kairen
0
110
Vishwakarma: Terraform modules for deploying EKS and Self-hosting Kubernetes
kairen
0
130
Chatbot as a Service on Container(Kubernetes)
kairen
0
1k
IT IRONMAN 2020
kairen
0
110
Advanced Kubernetes For UMC
kairen
0
190
Other Decks in Technology
See All in Technology
エンジニアリング戦略の作り方 / Crafting Engineering Strategy
iwashi86
21
6.8k
2026TECHFRESH畢業分享會 - AI 時代的人生存檔點
line_developers_tw
PRO
0
920
EventBridge Connection
_kensh
5
700
2026TECHFRESH畢業分享會 - Lightning Talk - 打造精準高效的 MCP 設計模式與測試實務
line_developers_tw
PRO
0
920
protovalidate-es を導入してみた
bengo4com
0
180
AIのReact習熟度を測る
uhyo
2
270
MCP Appsを作ってみよう
iwamot
PRO
4
580
スキルと MCP ツール、責務をどう分けるか? AI が迷わないインターフェース設計の戦略
cdataj
1
1k
AmazonRoute 53ではじめてのドメイン取得!HTTPS化までの道のりを整理してみた
usanchuu
3
140
AIソロプレナー時代に2ヶ月で20人増員した事業創造会社の開発組織の話
miyatakoji
0
640
2026 TECHFRESH 畢業分享會 - AI-Native 重塑軟體工程與虛擬講師
line_developers_tw
PRO
0
920
入門!AWS Blocks
ysuzuki
1
100
Featured
See All Featured
エンジニアに許された特別な時間の終わり
watany
107
250k
Organizational Design Perspectives: An Ontology of Organizational Design Elements
kimpetersen
PRO
1
720
Practical Orchestrator
shlominoach
191
11k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
122
22k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
9
1.4k
Pawsitive SEO: Lessons from My Dog (and Many Mistakes) on Thriving as a Consultant in the Age of AI
davidcarrasco
0
160
The Cult of Friendly URLs
andyhume
79
6.9k
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.7k
The Art of Programming - Codeland 2020
erikaheidi
57
14k
Connecting the Dots Between Site Speed, User Experience & Your Business [WebExpo 2025]
tammyeverts
11
940
Build your cross-platform service in a week with App Engine
jlugia
234
18k
How to Talk to Developers About Accessibility
jct
2
230
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!!