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
210
用 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
210
AWS Startup 2020 - AMIS
kairen
0
68
學習 Kubernetes 不是為了成為 YAML Engineer
kairen
0
310
How to make your container:Kubernetes is a bit more secure
kairen
0
180
Vishwakarma: Terraform modules for deploying EKS and Self-hosting Kubernetes(AWS))
kairen
0
88
Vishwakarma: Terraform modules for deploying EKS and Self-hosting Kubernetes
kairen
0
92
Chatbot as a Service on Container(Kubernetes)
kairen
0
910
IT IRONMAN 2020
kairen
0
79
Advanced Kubernetes For UMC
kairen
0
150
Other Decks in Technology
See All in Technology
ソフトウェアエンジニアの生成AI活用と、これから
lycorptech_jp
PRO
0
860
混合雲環境整合異質工作流程工具運行關鍵業務 Job 的經驗分享
yaosiang
0
160
Introduction to Sansan for Engineers / エンジニア向け会社紹介
sansan33
PRO
5
43k
初めてのDatabricks Apps開発
taka_aki
1
260
データ戦略部門 紹介資料
sansan33
PRO
1
3.8k
AIエージェントによる業務効率化への飽くなき挑戦-AWS上の実開発事例から学んだ効果、現実そしてギャップ-
nasuvitz
0
140
What's new in OpenShift 4.20
redhatlivestreaming
0
120
生成AIを安心して活用するために──「情報セキュリティガイドライン」策定とポイント
gree_tech
PRO
1
350
オブザーバビリティと育てた ID管理・認証認可基盤の歩み / The Journey of an ID Management, Authentication, and Authorization Platform Nurtured with Observability
kaminashi
1
140
AWS UG Grantでグローバル20名に選出されてre:Inventに行く話と、マルチクラウドセキュリティの教科書を執筆した話 / The Story of Being Selected for the AWS UG Grant to Attending re:Invent, and Writing a Multi-Cloud Security Textbook
yuj1osm
1
130
ハノーファーメッセ2025で見た生成AI活用ユースケース.pdf
hamadakoji
0
420
Oracle Base Database Service 技術詳細
oracle4engineer
PRO
12
81k
Featured
See All Featured
How to Ace a Technical Interview
jacobian
280
24k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
16
1.7k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
249
1.3M
Agile that works and the tools we love
rasmusluckow
331
21k
RailsConf 2023
tenderlove
30
1.3k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
30
2.9k
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
9
930
Understanding Cognitive Biases in Performance Measurement
bluesmoon
31
2.7k
The Pragmatic Product Professional
lauravandoore
36
7k
The MySQL Ecosystem @ GitHub 2015
samlambert
251
13k
KATA
mclloyd
PRO
32
15k
How To Stay Up To Date on Web Technology
chriscoyier
791
250k
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!!