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
5k
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
310
Helm Chart を Unit Test する / Unit Testing Helm Chart
daikurosawa
0
2k
Understanding CPU throttling in Kubernetes to improve application performance #k8sjp
daikurosawa
12
15k
Leader Election in Kubernetes #k8sjp
daikurosawa
5
10k
Argo CD 実践ガイド #k8sjp / Argo CD Practice Guide
daikurosawa
13
8.3k
図で理解する Descheduler #k8sjp #ymju / Introduction to Descheduler
daikurosawa
12
23k
GolangCI を使ってコードの品質を保ちながら快適な Golang 生活を送る話 #gounco / GolangCI
daikurosawa
4
5.8k
Introduction gRPC
daikurosawa
1
250
Go Cloud を触ってみる / gopher-dojo-lt
daikurosawa
2
2.1k
Other Decks in Programming
See All in Programming
Security_for_introducing_eBPF
kentatada
0
110
なまけものオバケたち -PHP 8.4 に入った新機能の紹介-
tanakahisateru
1
120
良いユニットテストを書こう
mototakatsu
5
1.9k
tidymodelsによるtidyな生存時間解析 / Japan.R2024
dropout009
1
760
テストケースの名前はどうつけるべきか?
orgachem
PRO
0
130
コンテナをたくさん詰め込んだシステムとランタイムの変化
makihiro
1
120
SymfonyCon Vienna 2025: Twig, still relevant in 2025?
fabpot
3
1.2k
CQRS+ES の力を使って効果を感じる / Feel the effects of using the power of CQRS+ES
seike460
PRO
0
110
複雑な仕様に立ち向かうアーキテクチャ
myohei
0
170
CSC305 Lecture 25
javiergs
PRO
0
130
ブラウザ単体でmp4書き出すまで - muddy-web - 2024-12
yue4u
2
460
Fibonacci Function Gallery - Part 1
philipschwarz
PRO
0
210
Featured
See All Featured
Build your cross-platform service in a week with App Engine
jlugia
229
18k
The Power of CSS Pseudo Elements
geoffreycrofte
73
5.4k
Put a Button on it: Removing Barriers to Going Fast.
kastner
59
3.6k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
26
1.5k
Statistics for Hackers
jakevdp
796
220k
Intergalactic Javascript Robots from Outer Space
tanoku
270
27k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
28
9.1k
Optimizing for Happiness
mojombo
376
70k
Building Adaptive Systems
keathley
38
2.3k
Designing Experiences People Love
moore
138
23k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
10
810
Docker and Python
trallard
42
3.1k
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 ܅Λ࡞ΕΔαΠτ
͓͠·͍