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の事始め
Search
Iku Yamamoto
February 02, 2018
Technology
4
1.5k
Kubernetesの事始め
Kubernetes(k8s)の初学者や導入検討者向けの資料
Iku Yamamoto
February 02, 2018
Tweet
Share
Other Decks in Technology
See All in Technology
RubyのWebアプリケーションを50倍速くする方法 / How to Make a Ruby Web Application 50 Times Faster
hogelog
2
860
開発生産性を上げながらビジネスも30倍成長させてきたチームの姿
kamina_zzz
1
1k
これまでの計測・開発・デプロイ方法全部見せます! / Findy ISUCON 2024-11-14
tohutohu
3
340
Incident Response Practices: Waroom's Features and Future Challenges
rrreeeyyy
0
150
データ活用促進のためのデータ分析基盤の進化
takumakouno
2
780
【Pycon mini 東海 2024】Google Colaboratoryで試すVLM
kazuhitotakahashi
2
270
いざ、BSC討伐の旅
nikinusu
2
730
20241108_CS_LLMMT
shigashiyama
0
260
[FOSS4G 2024 Japan LT] LLMを使ってGISデータ解析を自動化したい!
nssv
1
190
Deno+JSRでパッケージを作って公開する
askua
0
120
スクラムチームを立ち上げる〜チーム開発で得られたもの・得られなかったもの〜
ohnoeight
2
330
Shopifyアプリ開発における Shopifyの機能活用
sonatard
4
210
Featured
See All Featured
Building an army of robots
kneath
302
42k
Thoughts on Productivity
jonyablonski
67
4.3k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
33
1.8k
The Cult of Friendly URLs
andyhume
78
6k
Navigating Team Friction
lara
183
14k
Learning to Love Humans: Emotional Interface Design
aarron
273
40k
Git: the NoSQL Database
bkeepers
PRO
427
64k
Six Lessons from altMBA
skipperchong
27
3.5k
Statistics for Hackers
jakevdp
796
220k
Bootstrapping a Software Product
garrettdimon
PRO
305
110k
Building Better People: How to give real-time feedback that sticks.
wjessup
364
19k
How to Ace a Technical Interview
jacobian
276
23k
Transcript
Kubernetesͷίτ࢝Ί 2018/01/30 ࢁຊ ҭ 1
• ໊લ: ࢁຊ ҭ(twitter_id: @Mt_mo1019) • ݱࡏͷࣄ • RDB PaaS։ൃ
• ࠓ·Ͱ • PostgreSQLͷݕূ etc… Who am I ? 2
• kubernetes(k8s)ͷॳֶऀɾಋೖݕ౼ऀ͚ • k8sͬͯԿʁ • k8sΛͲ͏͍ͬͯͬͯΔͷʁ • k8sΛಋೖ͢ΔͱԿ͕ྑ͘/ѱ͘ͳΔͷʁ ࠓ͢͜ͱͱ 3
• ίϯςφཧͷ౷߹ج൫ • ίϯςφͷࣗಈσϓϩΠɾ෮چ • ج൫ and ίϯςφͷεέʔϧΞτ • ϩʔυόϥϯγϯά
• ൿີใίϯϑΟάͷ౷߹ཧ what is k8s? 4
Master Server Master Server k8sͷΞʔΩςΫνϟ 5 Master Nodes Nodes(Minion) Master
Server kubernetes cluster Node Server Node Server Node Server kubectl Pod Pod Pod Pod Auto Deploy
Master Server Master Server k8sͷΞʔΩςΫνϟ 6 Master Nodes Nodes(Minion) Master
Server kubernetes cluster Node Server Node Server Node Server Pod Pod Pod Pod Crash
Master Server Master Server k8sͷΞʔΩςΫνϟ 7 Master Nodes Nodes(Minion) Master
Server kubernetes cluster Node Server Node Server Node Server Pod Pod Pod Pod ReDeploy Crash Pod
• k8s͕ཧ͢ΔΦϒδΣΫτͷ࠷খ୯Ґ • Pod ≒ Container • PodίϯςφΛแ͢Δ • PodෳͷίϯςφΛ࣋ͯΔ
what is Pod? 8
what is Pod normally 9 Container ex) nginx Pod Container
ex) exporter, fluentd etc • αʔϏεͱड͚࣋ͭ ϝΠϯͷcontainer • αϒͷcontainer • agentܥͷϓϩηε Λड͚࣋ͭ • sidecarͱݴΘΕΔ
• σϓϩΠͷͨΊͷmanifestϑΝΠϧΛॻ͘ • ఆٛ͢Δ͜ͱଟذʹΘͨΔ • Podͷ༻్ʹΑΓछผΛม͑Δ • PodҎ֎ʹαʔϏεʹඞཁͳՃఆٛ • manifestΛ࡞Εଞͷk8s
clusterʹҠ২Ͱ͖Δ σϓϩΠ͢Δํ๏ 10
ओͳdeploy manifests 11 ఆٛ ֓ཁ Deployments ҰൠతͳPodͷσϓϩΠ StatefulSets StatefulͳΞϓϦέʔγϣϯͷσϓϩΠ DaemonSet
NodeશͷσϓϩΠ Jobs daemonize͠ͳ͍ΞϓϦͷσϓϩΠ CronJob Jobsͷఆظతͳ࣮ߦ Service PodͷΞΫηε੍ޚ ConfigMap PodʹΠϯδΣΫγϣϯ͢ΔϑΝΠϧఆٛ PersistentVolume ӬଓԽ͢ΔετϨʔδͷఆٛ
• ҰൠతͳσϓϩΠʹར༻ • ࢦఆͨ͠PodΛNodeʹσϓϩΠ • σϓϩΠ͢ΔPodͷࢦఆ Deployments 12
Master Server Master Server Deployments 13 Master Nodes Nodes(Minion) Master
Server kubernetes cluster Node Server Node Server Node Server Pod Pod Replicas=2
• StatefulͳΞϓϦέʔγϣϯͰར༻ • PodͷىಈΛॱ࣍ͬͯσϓϩΠ͢Δ • Podͷ໊લ͕Ұఆʹఆ·ΔͷͰ໊લղܾͷ લఏ͕Ͱ͖Δ • clusterߏ͕Ͱ͖ΔAppʹ༗ޮ StatefulSets
14
Master Server Master Server StatefulSets 15 Master Nodes Nodes(Minion) Master
Server kubernetes cluster Node Server Node Server Node Server 1st Pod Replicas=2
Master Server Master Server StatefulSets 16 Master Nodes Nodes(Minion) Master
Server kubernetes cluster Node Server Node Server Node Server 1st Pod Replicas=2 2nd Pod
• શNodesʹPodΛஔ͢Δ࣌ʹར༻ • NodeͰڞ௨తʹར༻͢ΔagentͳͲ • fluentdͳͲɺnodeʹແ݅ʹར༻͢ΔAppʹ༗ޮ DaemonSet 17
Master Server Master Server DaemonSet 18 Master Nodes Nodes(Minion) Master
Server kubernetes cluster Node Server Node Server Node Server Pod Pod Pod
• Ұ͚࣮ͩߦ͢Δॲཧʹར༻ • batchDatabaseͷmigrate࣌ͷscript࣮ߦ • Job͕ࣦഊͨ͠߹ʹ࠶࣮ߦͰ͖Δ Jobs 19
Master Server Master Server Jobs 20 Master Nodes Nodes(Minion) Master
Server kubernetes cluster Node Server Node Server Node Server Pod Ͳ͔͜ͷNodeͰ࣮ߦ
• JobsΛఆظ࣮ߦ͢Δࡍʹར༻ • ఆظbatchॲཧΛ࣮ߦͰ͖Δ • crontabΛClusterͰ੍ޚͰ͖Δ • ه๏crontabͱಉ༷ CronJob 21
Master Server Master Server CronJob 22 Master Nodes Nodes(Minion) Master
Server kubernetes cluster Node Server Node Server Node Server Pod Ͳ͔͜ͷNodeͰJobΛىಈ ఆظ࣮ߦ
• NodeͷΞΫηεͱPodΛ݁ͼ͚ͭΔ • ղ์͢ΔαʔϏε(Pod)Λఆٛ • Pod͕ଞͷNodeʹҠͬͯै͢Δ • ෳPod͕͋Δ߹ɺΑ͠ͳʹৼΓ͚Δ Service 23
Service 24 Nodes(Minion) kubernetes cluster Node Server Node Server Node
Server Pod Pod Service ͲͷNodeʹΞΫηεͯ͠ ݁ͼ͍ͭͨPodʹಧ͘
• PodʹfileΛInjectionͰ͖Δ • ConfigΛfileͰඞཁͱ͢ΔAppͰར༻ ConfigMap 25
• σʔλӬଓԽ͕Ͱ͖ΔετϨʔδͷఆٛ • Access Mode͕͋ΔͷͰݕ౼͕ඞཁ • https://kubernetes.io/docs/concepts/storage/ persistent-volumes/#access-modes Persistent Volumes
26
• manifestϑΝΠϧ͕࡞ڥ͝ͱʹͰ͖Δ • devڥɺtestڥɺproductionڥ etc… • ಉ͡ఆٛ(yaml)Λཧ͢Δ͜ͱʹͳΔ • ಉ͡هड़templateԽ͍ͨ͠ manifestΛ࡞͍ͬͯ͘ͱى͖Δ
27
• manifestϑΝΠϧΛtemplateԽͯ͠ཧ • https://github.com/kubernetes/helm • Podͷىಈ/ߋ৽લޙʹhookͯ͠JobΛڬΊΔ what is helm? 28
• Go templateΛར༻ͨ͠manifestཧ • templatesͱvaluesͷ2ϑΝΠϧͰཧ • values͚ͩΛڥ͝ͱʹมߋ͢Δ • pre/postॲཧΛ࣮ࢪͰ͖Δ what
is helm? 29
• ެࣜDocumentΛಡΉ(ࣗಈ༁Ͱ݁ߏ៉ྷ) • https://kubernetes.io/docs/home/ • ଞਓͷmanifestΛಡΈࠐΉ k8sͷา͖ํ 30
• ίϯςφͳͷͰىಈ͕ૣ͍ • ։ൃऀͷ༗ޮͳػೳ͕ଟ͍ • εέʔϧΞτ • ো࣌ͷࣗಈFailOver͕Α͍ • CronJobͷΫϥελ੍ޚ
• ͲͷNodeʹΞΫηεͯ͠Podʹ౸ୡͰ͖Δ • Document͕ἧ͍ͬͯΔɻӳޠ͕៉ྷɻ • ॳظֶशίετ͕ߴ͍ ར༻ऀͱͯ͠ͷk8sͷॴײ 31
• ։ൃڥͷk8sͷ࠶ߏங • Stagingڥͷނো ӡ༻தʹىͬͨ͜͜ͱ 32
• ։ൃڥͷഁଛ • Podؒͷ௨৴͕औΕͳ͘ͳͬͨ • ࠶ߏஙͱ෮چͷൺֱͰ࠶ߏஙͨ͠ k8sͷ࠶ߏங 33
k8sͷߏஙํ๏ 34 ߏஙํ๏ Pros. Cons. ࣗલͷansible ࣗલͰ࡞ΕΔͷͰॊೈ ै͕େม kubeadm kubenetesຊՈͷϨϙδτϦ
શͯͷΦϖϨʔγϣϯͷ ίʔυԽΛࢦ͢ https://github.com/kubernetes/ kubeadm ·ͩ։ൃ్த starগͳΊ kube-spray star͕ଟ͍ ෳͷύλʔϯʹରԠͯ͠ ͍Δ https://github.com/kubernetes- incubator/kubespray ຊՈϨϙδτϦͰͳ͍ playbookࣗମෳࡶ
• Podͷ໊લղܾ͕Ͱ͖ͳ͘ͳͬͨ • kube-dnsͱNWPluginͷෳ߹ࣄҊ • ͷݪҼෆ໌ͳ·· • tokenͷ࠶ൃߦPodͷ࠶ੜͳͲɺ༷ʑͳ ରԠ(issuesΛࢀߟ)Ͱ෮چ Stagingڥͷނো
35
• ղܾʹ3͔͔ͬͨ • Podͷࣗಈ෮چʹΑΓσϓϩΠ͍ͯͨ͠ϛυ ϧΣΞͷΫϥελ่յ • ͱͱίϯςφલఏͷઃܭʹͳ͍ͬͯͳ ͍ΞϓϦҙ StagingڥͷނোͷӨڹ 36
• ྑ͍ͱ͜Ζ • ։ൃεϐʔυ͕ͱͯૣ͍ • ػೳଟ͘ἧ͍ͬͯͯศར • ѱ͍ͱ͜Ζ • ॳظֶशίετ͕ߴ͍
• ӡ༻ൣғ͕ଟذʹΔ • NW plugin͕Կ͕͍͍͔Θ͔Βͳ͍ • ReadWriteManyʹରԠͨ͠PersistentVolume͕গͳ͍ ॴײ 37
• k8sΛར༻͢ΔͳΒ • GKEͳͲͷڊਓͷݞͷ্ʹཱͭ • ࣗ৫Ͱ͏ͳΒઐ༻ͷӡ༻෦ୂΛ༻ҙ͢Δ • ։ൃऀʹͱͯخ͍͠ػೳ͕ଟ͍ • ίϯςφͰͷ։ൃ͕Ͱ͖ΔΤϯδχΞ͕ඞਢ
૯ׅ 38