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
alecthomas/kong はいいぞ / kamakura.go#7
fujiwara3
1
300
PHPからGoへのマイグレーション for DMMアフィリエイト
yabakokobayashi
1
180
サイボウズフロントエンドエキスパートチームについて / FrontendExpert Team
cybozuinsideout
PRO
5
38k
フロントエンド設計にモブ設計を導入してみた / 20241212_cloudsign_TechFrontMeetup
bengo4com
0
1.9k
re:Invent 2024 Innovation Talks(NET201)で語られた大切なこと
shotashiratori
0
320
Turing × atmaCup #18 - 1st Place Solution
hakubishin3
0
500
サイバー攻撃を想定したセキュリティガイドライン 策定とASM及びCNAPPの活用方法
syoshie
3
1.4k
UI State設計とテスト方針
rmakiyama
2
690
1等無人航空機操縦士一発試験 合格までの道のり ドローンミートアップ@大阪 2024/12/18
excdinc
0
170
非機能品質を作り込むための実践アーキテクチャ
knih
5
1.6k
組織に自動テストを書く文化を根付かせる戦略(2024冬版) / Building Automated Test Culture 2024 Winter Edition
twada
PRO
18
5.1k
Work as an App Engineer
lycorp_recruit_jp
0
290
Featured
See All Featured
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
32
2.7k
Rebuilding a faster, lazier Slack
samanthasiow
79
8.7k
Faster Mobile Websites
deanohume
305
30k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
28
2.1k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
26
1.5k
Docker and Python
trallard
42
3.1k
Bash Introduction
62gerente
609
210k
Put a Button on it: Removing Barriers to Going Fast.
kastner
59
3.6k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
665
120k
Why Our Code Smells
bkeepers
PRO
335
57k
Into the Great Unknown - MozCon
thekraken
33
1.5k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
251
21k
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