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
170
用 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
170
AWS Startup 2020 - AMIS
kairen
0
50
學習 Kubernetes 不是為了成為 YAML Engineer
kairen
0
260
How to make your container:Kubernetes is a bit more secure
kairen
0
150
Vishwakarma: Terraform modules for deploying EKS and Self-hosting Kubernetes(AWS))
kairen
0
74
Vishwakarma: Terraform modules for deploying EKS and Self-hosting Kubernetes
kairen
0
64
Chatbot as a Service on Container(Kubernetes)
kairen
0
840
IT IRONMAN 2020
kairen
0
57
Advanced Kubernetes For UMC
kairen
0
120
Other Decks in Technology
See All in Technology
エンジニアリング価値を黒字化する バリューベース戦略を用いた 技術戦略策定の道のり
kzkmaeda
6
2.8k
Amazon Aurora のバージョンアップ手法について
smt7174
2
150
ウォンテッドリーのデータパイプラインを支える ETL のための analytics, rds-exporter / analytics, rds-exporter for ETL to support Wantedly's data pipeline
unblee
0
130
ディスプレイ広告(Yahoo!広告・LINE広告)におけるバックエンド開発
lycorptech_jp
PRO
0
380
Snowflake ML モデルを dbt データパイプラインに組み込む
estie
0
100
Exadata Database Service on Cloud@Customer セキュリティ、ネットワーク、および管理について
oracle4engineer
PRO
2
1.5k
Visualize, Visualize, Visualize and rclone
tomoaki0705
9
83k
Amazon Q Developerの無料利用枠を使い倒してHello worldを表示させよう!
nrinetcom
PRO
2
120
AIエージェント入門
minorun365
PRO
31
18k
NFV基盤のOpenStack更新 ~9世代バージョンアップへの挑戦~
vtj
0
360
システム・ML活用を広げるdbtのデータモデリング / Expanding System & ML Use with dbt Modeling
i125
1
330
あなたが人生で成功するための5つの普遍的法則 #jawsug #jawsdays2025 / 20250301 HEROZ
yoshidashingo
2
300
Featured
See All Featured
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
44
7k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
27
1.9k
Designing for Performance
lara
604
68k
jQuery: Nuts, Bolts and Bling
dougneiner
63
7.7k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
30
2.2k
Code Review Best Practice
trishagee
67
18k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
40
2k
It's Worth the Effort
3n
184
28k
Building an army of robots
kneath
303
45k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
49
2.3k
Rails Girls Zürich Keynote
gr2m
94
13k
Docker and Python
trallard
44
3.3k
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!!