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.9k
Argo CD 実践ガイド #k8sjp / Argo CD Practice Guide
daikurosawa
13
8.2k
図で理解する 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
2.1k
Other Decks in Programming
See All in Programming
「今のプロジェクトいろいろ大変なんですよ、app/services とかもあって……」/After Kaigi on Rails 2024 LT Night
junk0612
5
2.1k
AWS Lambdaから始まった Serverlessの「熱」とキャリアパス / It started with AWS Lambda Serverless “fever” and career path
seike460
PRO
1
260
LLM生成文章の精度評価自動化とプロンプトチューニングの効率化について
layerx
PRO
2
190
距離関数を極める! / SESSIONS 2024
gam0022
0
280
What’s New in Compose Multiplatform - A Live Tour (droidcon London 2024)
zsmb
1
470
【Kaigi on Rails 2024】YOUTRUST スポンサーLT
krpk1900
1
330
ピラミッド、アイスクリームコーン、SMURF: 自動テストの最適バランスを求めて / Pyramid Ice-Cream-Cone and SMURF
twada
PRO
10
1.3k
ECS Service Connectのこれまでのアップデートと今後のRoadmapを見てみる
tkikuc
2
250
Nurturing OpenJDK distribution: Eclipse Temurin Success History and plan
ivargrimstad
0
890
macOS でできる リアルタイム動画像処理
biacco42
9
2.4k
A Journey of Contribution and Collaboration in Open Source
ivargrimstad
0
890
Kaigi on Rails 2024 〜運営の裏側〜
krpk1900
1
200
Featured
See All Featured
A Modern Web Designer's Workflow
chriscoyier
693
190k
[RailsConf 2023] Rails as a piece of cake
palkan
52
4.9k
The Cost Of JavaScript in 2023
addyosmani
45
6.7k
Docker and Python
trallard
40
3.1k
How to Ace a Technical Interview
jacobian
276
23k
Product Roadmaps are Hard
iamctodd
PRO
49
11k
Build The Right Thing And Hit Your Dates
maggiecrowley
33
2.4k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
25
1.8k
The Power of CSS Pseudo Elements
geoffreycrofte
73
5.3k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
131
33k
A designer walks into a library…
pauljervisheath
203
24k
Practical Orchestrator
shlominoach
186
10k
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 ܅Λ࡞ΕΔαΠτ
͓͠·͍