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
Kubernetes のソースコードとの付き合い方 #gounco / Kubernetes ...
Search
d-kuro
May 27, 2019
Programming
24
4.9k
Kubernetes のソースコードとの付き合い方 #gounco / Kubernetes source code reading
Go(Un)Conference(Goあんこ)LT大会 6kg で発表した資料です
https://gounconference.connpass.com/event/129090/
d-kuro
May 27, 2019
Tweet
Share
More Decks by d-kuro
See All by d-kuro
kube-state-metrics Sharding
daikurosawa
0
290
Helm Chart を Unit Test する / Unit Testing Helm Chart
daikurosawa
0
1.9k
Understanding CPU throttling in Kubernetes to improve application performance #k8sjp
daikurosawa
12
14k
Leader Election in Kubernetes #k8sjp
daikurosawa
5
9.8k
Argo CD 実践ガイド #k8sjp / Argo CD Practice Guide
daikurosawa
13
8.1k
図で理解する Descheduler #k8sjp #ymju / Introduction to Descheduler
daikurosawa
12
23k
GolangCI を使ってコードの品質を保ちながら快適な Golang 生活を送る話 #gounco / GolangCI
daikurosawa
4
5.8k
Introduction gRPC
daikurosawa
1
240
Go Cloud を触ってみる / gopher-dojo-lt
daikurosawa
2
2k
Other Decks in Programming
See All in Programming
Cloud Adoption Frameworkにみる組織とクラウド導入戦略(縮小版)
tomokusaba
1
180
CSC509 Lecture 03
javiergs
PRO
0
140
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
8
610
AWS CDKを用いたセキュアなCI/CDパイプラインの構築 / Build a secure CI/CD pipeline using AWS CDK
seike460
PRO
3
610
Subclassing, Composition, Python, and You
hynek
3
160
Делим тесты между QA и разработчиком
lamodatech
0
550
GitHub Copilot Workspace で我々のアプリ開発がどう変わるのか?
shuyakinjo
0
910
ECS向けのドリフト検知機構を実装してみた
tkikuc
0
280
M5Stack に色々な M5ユニットをつないで扱う為の新たなアプローチ
gob
0
210
CSC509 Lecture 02
javiergs
PRO
0
160
Интеграционное тестирование: как приручить хаос
lamodatech
0
560
Compose Multiplatform과 Ktor로 플랫폼의 경계를 넘어보자
kwakeuijin
0
260
Featured
See All Featured
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
355
29k
Adopting Sorbet at Scale
ufuk
73
9k
How To Stay Up To Date on Web Technology
chriscoyier
787
250k
5 minutes of I Can Smell Your CMS
philhawksworth
202
19k
Typedesign – Prime Four
hannesfritz
39
2.3k
From Idea to $5000 a Month in 5 Months
shpigford
381
46k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
4
120
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
3
230
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
105
48k
Fontdeck: Realign not Redesign
paulrobertlloyd
81
5.2k
Being A Developer After 40
akosma
84
590k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
280
13k
Transcript
Kubernetes ͷ ιʔείʔυͱͷ ͖߹͍ํ 19/05/27 Go(Un)ConferenceʢGo͋Μ͜ʣLTେձ 6kg @ponde_m
None
ࠓ͢͜ͱ • Kubernetes ͷΞʔΩςΫνϟʹ͍ͭͯ • Kubernetes ͷιʔείʔυΛಡΉࡍʹ ʹཱͭ Go ͷษڧձ͚ͩͲ
Kubernetes ͱͳΜͧ Έ͍ͨͳ͕݁ߏ͋Γ·͢ (Gopher ͘Μ͍ͬͺ͍ग़·͢)
Kubernetes ͱ
Kubernetes ͱ • ίϯςφΛಈ͔ͨ͢ΊͷϓϥοτϑΥʔϜ • ίϯςφΛ͍͍ײ͡ʹӡ༻͢ΔͨΊͷػೳΛ ͍ͬͺ͍͍࣋ͬͯΔ • σϓϩΠ, εέʔϦϯά,
ࣗݾम෮ etc… k8s ͬͯॻ͔ΕͨΓ͢Δͷ Kubernetes ͕ (k + 8 จࣈ + s) ͔ͩΒ
Kubernetes ͷ ΞʔΩςΫνϟ
• ΞʔΩςΫνϟʹ͍ͭͯཧղ͢Δͱ, ࣗͷಡΈ͍ͨ෦ͷίʔυ͕ Ͳͷίϯϙʔωϯτʹ͋Δͷ͔Θ͔Δ • ͦΕͧΕͷίϯϙʔωϯτͱ ͦͷʹ͍ͭͯཧղ͠Α͏ Kubernetes ͷΞʔΩςΫνϟ ࣍ͷϖʔδ͔Βͬ͘͟Γͱ
ਤΛ༻͍ͯઆ໌͠·͢
Kubernetes ͷΞʔΩςΫνϟ Master Node Node API API
Kubernetes ͷΞʔΩςΫνϟ Master Node Node API API
Kubernetes ͷΞʔΩςΫνϟ API Server Contoroller Manager Scheduler etcd
Kubernetes ͷΞʔΩςΫνϟ API Server Contoroller Manager Scheduler etcd API Server
Kubernetes ͷ ϦιʔεΛཧ͢Δ API Server શͯͷϦιʔεૢ࡞ API Server Λܦ༝ͯ͠ߦ͏
Kubernetes ͷΞʔΩςΫνϟ API Server Contoroller Manager Scheduler etcd Contoroller Manager
API Server ͰϦιʔεใͷ CRUD ͙Β͍͔͠ߦͳͬͯ ͓ΒͣɺϦιʔεʹର͢Δ࣮ࡍͷॲཧͷத Controller ͱݺΕΔίϯϙʔωϯτ͕ඇಉظͰߦͳ͍ͬͯΔ Controller (goroutine) Controller (goroutine) Controller (goroutine) ىಈ
Kubernetes ͷΞʔΩςΫνϟ API Server Contoroller Manager Scheduler etcd Scheduler Pod
(ίϯςφ) ΛϊʔυׂΓͯΔ
Kubernetes ͷΞʔΩςΫνϟ API Server Contoroller Manager Scheduler etcd ϦιʔεͷӬଓԽʹΘΕΔࢄ KVS
etcd
Kubernetes ͷΞʔΩςΫνϟ Master Node Node API API
Kubernetes ͷΞʔΩςΫνϟ API Server kube-proxy Pod Pod Pod Internet kubelet
Kubernetes ͷΞʔΩςΫνϟ API Server kubelet kube-proxy Pod Pod Pod Internet
kubelet ֤ϊʔυͰಈ࡞͢Δ Pod Λىಈ, ཧ͢ΔΤʔδΣϯτ kubelet
Kubernetes ͷΞʔΩςΫνϟ API Server kube-proxy Pod Pod Pod Internet kube-proxy
kubelet ֤ϊʔυͰಈ࡞͢Δ Service ͷఆٛΛݩʹϧʔςΟϯά ͯ͘͠ΕΔωοτϫʔΫϓϩΩγ kube-proxy
Kubernetes ͷΞʔΩςΫνϟ API Server kube-proxy Pod Pod Pod Internet Pod
Pod Pod kubelet Container Runtime Docker Ҏ֎ಈ͘ Pod Pod Pod
Kubernetes ͷ ιʔείʔυʹ͍ͭͯ
Kubernetes ͷιʔείʔυʹ͍ͭͯ • github.com/kubernetes/kubernetes • Go Modules ରԠͯ͠ΔͷͰ go mod
ίϚϯ υΛ࣮ߦ͢ΔͱϏϧυͰ͖ΔΑ͏ʹͳΔ • ಡΉ࣌ IDE ͰίʔυδϟϯϓΛ͓͏ 4݄͙Β͍ʹ Go Modules ରԠͨ͠ https://github.com/kubernetes/kubernetes/pull/74877
Kubernetes ͷιʔείʔυʹ͍ͭͯ • ϒϥβ͔Β͏࣌ SourceGraph Λ ೖΕΔͱศར • ϒϥβ͔Β Code
Jump Ͱ͖Δ • https://about.sourcegraph.com/
Kubernetes ͷιʔείʔυʹ͍ͭͯ • Kubernetes ͷίϯϙʔωϯτͷ࣮Ͱ github.com/spf13/cobra ͕ΘΕ͍ͯΔ • Server ͱͯ͠ৼΔ͏ͷ
cobra Ͱ࣮͞Ε͍ͯΔ • ࣮ߦ࣌ͷ Option ͰύϥϝʔλΛͨ͠ΓͰ͖Δ
main package Ͳ͜ʹ͋Δͷ͔
main package Ͳ͜ʹ͋Δͷ͔ • cmd package ͷதΛݟΔͱ֤ίϯϙʔωϯτ͝ ͱʹ͞Βʹ package ͕͔Ε͍ͯΔ
github.com/kubernetes/ kubernetes/cmd/ ͖ͬ͞ݟͨΑ͏ͳ໊લ͕ͪΒ΄Β
• main package ͦͷԼʹ͋Δ main package Ͳ͜ʹ͋Δͷ͔
None
Controller ʹ͍ͭͯ
Kubernetes ͷΞʔΩςΫνϟ API Server Contoroller Manager Scheduler etcd Contoroller Manager
API Server ͰϦιʔεใͷ CRUD ͙Β͍͔͠ߦͳͬͯ ͓ΒͣɺϦιʔεʹର͢Δ࣮ࡍͷॲཧͷத Controller ͱݺΕΔίϯϙʔωϯτ͕ඇಉظͰߦͳ͍ͬͯΔ Controller (goroutine) Controller (goroutine) Controller (goroutine) ىಈ ͓͞Β͍
• Ϧιʔεʹର͢Δ࣮ࡍͷॲཧͷத Controller ͱݺΕΔί ϯϙʔωϯτ͕ඇಉظͰߦͳ͍ͬͯΔ • ྫ͑ Deployment ͷಈ͖ͷ࣮͕ݟ͍ͨʂ ͬͯͳͬͨ࣌ʹ
API Server ͷίʔυΛಡΈʹߦͬͯ Կॻ͍ͯͳ͍ • Controller Λಡ͏ Controller ʹ͍ͭͯ ͜ͷ͜ͱΛΒͣʹ࠷ॳ API Server ͷίʔυಡΜͰ·ͨ͠
Controller ʹ͍ͭͯ Contoroller Manager Controller (goroutine) Controller (goroutine) Controller (goroutine)
ىಈ • ࣮ࡍʹͲΜͳײ͡ͳͷ͔ίʔυͰݟͯΈΔ
͜Μͳײ͡ͷ map Ͱఆٛ͞Ε͍ͯΔ https://github.com/kubernetes/kubernetes/blob/v1.14.2/ cmd/kube-controller-manager/app/ controllermanager.go#L341-L384
Controller ͷ໊લͱ Controller Λ࣮ߦ͢ΔͨΊͷؔ
func StartControllers() Ͱ Controller ΛൃՐ (ΊͬͪΌίʔυͬͯΔ) https://github.com/kubernetes/kubernetes/blob/v1.14.2/ cmd/kube-controller-manager/app/ controllermanager.go#L461-L501
͖ͬ͞ͷ map Λ for Ͱճͯ͠ ͜͜Ͱ Controller ͷ࣮ߦؔΛݺΜͰΔ
ྫͱͯ͠ Deployment ͷ Controller ͷ࣮ߦؔ https://github.com/kubernetes/kubernetes/blob/v1.14.2/ cmd/kube-controller-manager/app/apps.go#L82-L97
ίϯετϥΫλͰ Controller Λ࡞ͬͯ goroutine Ͱ Controller Λ࣮ߦ
·ͱΊ • Kubernetes ͷΞʔΩςΫνϟ ͓֮͑ͯ͘ͱʹཱͭ • Kubernetes ͷιʔείʔυҙ֎ʹಡΊΔ • Go
ಡΈ͍͢ ΈΜͳಡ͏
͓·͚
ʹཱͭϦϯΫͱ͔ • github.com/jamiehannaford/what-happens-when-k8s • Kubernetes ͕ىಈ͔ͯ͠ΒͲΜͳ͜ͱΛ͍ͯ͠Δ͔ ιʔείʔυϨϕϧͰղઆͯ͘͠ΕΔ • ͳΜͱຊޠ ver
͋Δ • ιʔείʔυͷϦϯΫ͕ݹ͔ͬͨΓ, ϦϯΫΕͩͬͨ Γ͢ΔͷͰ PR Λग़ͦ͏! (ग़ͯ͠Δ)
ʹཱͭϦϯΫͱ͔ • https://gopherize.me/ • Զ͚ͩͷ࠷ߴʹ͔Θ͍͍ Gopher ܅Λ࡞ΕΔαΠτ
͓͠·͍