Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
RubyでKubernetesプログラミング
Search
Satoru Takeuchi
PRO
January 18, 2025
Technology
280
4
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
RubyでKubernetesプログラミング
北陸三県.rb Lightning Talks in Kanazawaの発表スライドです。
https://kzrb.doorkeeper.jp/events/180430
Satoru Takeuchi
PRO
January 18, 2025
More Decks by Satoru Takeuchi
See All by Satoru Takeuchi
119-多機能ファイルシステムBtrfs_のコピー.pdf
sat
PRO
1
75
Linuxカーネルの インタフェースは変わりうる?
sat
PRO
1
100
あなたの知らないバージョン命名規則
sat
PRO
3
920
Rook: Intro and Deep Dive with Ceph
sat
PRO
1
69
Machine Check Exception
sat
PRO
2
68
バイナリダンプの模様を読む
sat
PRO
0
110
cpコマンドはディスク上でデータを コピーしないことがある
sat
PRO
3
100
114-ファイルのshallow_copy.pdf
sat
PRO
2
59
113-Btrfsのスナップショット.pdf
sat
PRO
0
43
Other Decks in Technology
See All in Technology
[AWS 秋のクラウドオペレーション祭り 2026]AWS DevOps Agentで変わるリリースと運用対応 ~リリース管理機能と Directed actions のご紹介~
furuton
2
850
全社共通データ基盤をつくる。ソニーのDatabricks活用とデータガバナンス設計の裏側
sony
0
420
2026-10-01_MagicPod_QAハーネスエンジニアリングとQA組織の未来像
ynisqa1988
1
530
検証フェーズはAIの回答を判断するための学習機会
toru_kubota
2
500
自律型 AI をセキュアに実装!Gemini と MIG で作る動的コード実行環境
recruitengineers
PRO
1
210
組み立てて楽しむ AWS Blocks 入門
kmiya84377
0
210
AI時代に必要な脅威モデリング― 変化の速度に負けない理解とリスク判断
masakane55
4
970
IR Today: Theory, Practice, and Agents
dtunkelang
0
350
あなたの知らないAmazon VPC Route Server/Amazon VPC Route Server you don't know about
masakiokuda
2
220
FactoryBotアンチパターン / factory_bot anti-patterns
toshimaru
0
130
SDDの運用にめげずに向き合った話
sansantech
PRO
0
130
「とりあえず動く」の先へ。 AI時代のチーム開発と内部設計/2026-slsdays
slsops
0
150
Featured
See All Featured
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
287
14k
Design in an AI World
tapps
1
350
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
35
2.9k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
141
35k
Groundhog Day: Seeking Process in Gaming for Health
codingconduct
0
390
StorybookのUI Testing Handbookを読んだ
zakiyama
31
7k
Agile Leadership in an Agile Organization
kimpetersen
PRO
0
270
Large-scale JavaScript Application Architecture
addyosmani
515
110k
AI: The stuff that nobody shows you
jnunemaker
PRO
10
1.1k
Organizational Design Perspectives: An Ontology of Organizational Design Elements
kimpetersen
PRO
1
840
Efficient Content Optimization with Google Search Console & Apps Script
katarinadahlin
PRO
1
910
More Than Pixels: Becoming A User Experience Designer
marktimemedia
3
550
Transcript
Rubyで Kubernetesプログラミング Jan. 18th, 2025 Satoru Takeuchi X: satoru_takeuchi 1
• sat(武内 覚) ◦ X: satoru_takeuchi • 会社員 ◦ Kubernetes(K8s)上で動く分散ストレージの開発
• 個人事業主 ◦ 本や記事の執筆 2
懺悔の時間 • Rubyで実用的なプログラムを書いたのが20年前 • kanazawa.rbに参加してから6年、Rubyの話をしたことがほぼ無い 3
何しに来たの? 4
何しに来たの? • 3県合同Rubyイベントなので久々にRubyを触ってみることにした • K8sクライアントをRubyで書くことにした 5
KubernetesのRubyクライアント探し • 公式サイトにサポートされているライブラリが載っていた ◦ https://kubernetes.io/docs/reference/using-api/client-libraries/ … 6
メンテされてなかった • 最終コミットは4年前 ◦ https://github.com/kubernetes-client/ruby 7
メンテされてなかった • 最終コミットは4年前 ◦ https://github.com/kubernetes-client/ruby 8 ☠終了☠
まだ終わらんよ • “Community-maintained client libraries”節の中にk8s-rubyというものを発見 ◦ https://github.com/k8s-ruby/k8s-ruby • 過去にKontenaという会社が開発していて、会社close後にforkしてコミュニティベー スで開発が続いているらしい
9
動作環境 • OS: Ubuntu 24.0.1 • kind: v0.26.0 • kubernetes:
v1.32.0 • ruby: 3.2.3 • k8s-ruby: v0.16.0 10
比較対象: Go(client-go)でpod一覧表示 package main import ( "context" "fmt" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes" "k8s.io/client-go/tools/clientcmd" ) func main() { config , _ := clientcmd .BuildConfigFromFlags ("", "/home/sat/.kube/config" ) clientset , _ := kubernetes .NewForConfig (config ) pods, _ := clientset .CoreV1 ().Pods("").List(context .Background (), metav1 .ListOptions {}) for _, pod := range pods.Items { fmt.Printf ("ns=%s, name= %s\n", pod.GetNamespace (), pod.GetName ()) } } 11
k8s-rubyならこうなる • まあまあ短くなる • 実行結果 12 require 'k8s-ruby' client =
K8s::Client .config( K8s::Config .load_file( ’/home/sat/.kube/config' )) client.api( 'v1').resource( 'pods' , namespace: 'default' ).list().each do |pod| puts "ns=#{pod.metadata.namespace }, pod= #{pod.metadata.name }" end $ bundle exec ./test.rb ns=default, name=nginx ns=default, name=nginx2
コントローラも書けるよ • K8sのコントローラとは、あるリソースの状態を監視してなんらかのアクションをする プログラム • 今回はpodに心霊現象を起こすコントローラを作る 13
ソース #!/usr/bin/ruby require 'k8s-ruby' client = K8s::Client .config( K8s::Config .load_file(
’/home/sat/.kube/config' )) client.api( 'v1').resource( 'pods' , namespace: 'default' ).watch() do |event | pod = client.api( 'v1').resource( 'pods' , namespace: 'default' ).get(event.resource.metadata.name) pod.metadata. annotations[ 'message' ] = "???" client.api( 'v1').resource( 'pods' , namespace: 'default' ).update_resource (pod) end 14
今は霊圧を感じない… 15 $ kubectl get pod nginx -o yaml apiVersion:
v1 kind: Pod metadata: annotations: … spec:
コントローラを実行して… 16 $ kubectl get pod nginx -o yaml …
$ bundle exec ./spiritual-pod-controller.rb &
podをリストすると… 17 … $ kubectl get pod nginx -o yaml
怪奇現象が…! 18 … $ kubectl get pod nginx -o yaml
apiVersion: v1 kind: Pod metadata: annotations: … spiritual-message: タスケテ... … spec:
まとめ • RubyでK8sプログラミングができることがわかった • どれだけ実用に耐えるかはよくわからない ◦ 開発が活発じゃなさそう ◦ ドキュメントが皆無 ◦
ここ数年追加された機能には対応していなさそう • サンプルコード ◦ https://github.com/satoru-takeuchi/test-k8s-ruby 19