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
130
用 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
130
AWS Startup 2020 - AMIS
kairen
0
38
學習 Kubernetes 不是為了成為 YAML Engineer
kairen
0
230
How to make your container:Kubernetes is a bit more secure
kairen
0
130
Vishwakarma: Terraform modules for deploying EKS and Self-hosting Kubernetes(AWS))
kairen
0
64
Vishwakarma: Terraform modules for deploying EKS and Self-hosting Kubernetes
kairen
0
43
Chatbot as a Service on Container(Kubernetes)
kairen
0
770
IT IRONMAN 2020
kairen
0
49
Advanced Kubernetes For UMC
kairen
0
110
Other Decks in Technology
See All in Technology
FrontDoorとWebAppsを組み合わせた際のリダイレクト処理の注意点
kenichirokimura
1
530
TechFeed Experts Night#27 〜 フロントエンドフレームワーク最前線 (Svelte)
baseballyama
1
530
開発生産性大幅アップ!Postman VS Code拡張機能
nagix
2
380
AOAI をきっかけに 社内の Azure 管理を見直した話
recruitengineers
PRO
1
300
プラットフォームってつくることより計測することが重要なんじゃないかという話 / Platform Engineering Meetup #8
taishin
1
370
現代CSSフレームワークの内部実装とその仕組み
poteboy
7
3.6k
20240418_Google ColabにLLMが搭載されたようなのでPython x データ分析の勉強方法を考えてみる
doradora09
0
140
リテール金融(キャッシュレス・ネット銀行・ネット証券)の競争環境と経済圏
8maki
0
1.2k
APIファーストなプロダクトマネジメントの実践 〜SaaSus Platformでの例〜 / "Practicing API-First Product Management - An Example with SaaSus Platform
oztick139
0
110
一生覚えておきたい「システム開発=コミュニケーション」〜初めての実務案件振り返りLT〜
maimyyym
1
160
検証を通して見えてきたTiDBの性能特性
lycorptech_jp
PRO
6
3.8k
VSCodeの拡張機能を作っている話
ebarakazuhiro
1
530
Featured
See All Featured
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
20
1.9k
Building Applications with DynamoDB
mza
88
5.6k
Bootstrapping a Software Product
garrettdimon
PRO
302
110k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
352
28k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
274
13k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
7
1k
Fireside Chat
paigeccino
21
2.6k
Building Your Own Lightsaber
phodgson
99
5.7k
4 Signs Your Business is Dying
shpigford
175
21k
WebSockets: Embracing the real-time Web
robhawkes
59
7k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
226
51k
Designing for humans not robots
tammielis
248
25k
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!!