タップル誕生: オンプレからAWS Fargateまで @ JAWS DAYS 2020
by
Tamirlan 893 Torgayev
Link
Embed
Share
Beginning
This slide
Copy link URL
Copy link URL
Copy iframe embed code
Copy iframe embed code
Copy javascript embed code
Copy javascript embed code
Share
Tweet
Share
Tweet
Slide 1
Slide 1 text
λοϓϧੜ: ΦϯϓϨ͔ΒAWS Fargate·Ͱ גࣜձࣾαΠόʔΤʔδΣϯτ ٕज़ຊ෦ αʔϏεϦϥΠΞϏϦςΟάϧʔϓ ϓϩάϥϛϯάϠΫβ (@prog893)
Slide 2
Slide 2 text
ࣗݾհ • Torgayev Tamirlan / ϓϩάϥϛϯάϠΫβ / @prog893 τ ϧ Ψ Τ ϑ λ ϝ ϧ ϥ ϯ • αΠόʔΤʔδΣϯτ ٕज़ຊ෦ αʔϏεϦϥΠΞϏϦςΟάϧʔϓ (௨শ SRG) • झຯ: Χϝϥ • ͖ͳͷ: TerraformɺPythonɺElasticsearchɺServerless ❤ • ͖ͳAWSͷαʔϏε: ECS • ΞϧόΠτ 14ϲ݄ 2018 ৽ଔೖࣾ (ࣗশ4) AWA վળʢͦͷ1ɺͦͷ2ʣɺτϧςɺCARTEɺREQU ্ཱͪ͛αϙʔτ ݱ AWAɺλοϓϧੜɺCROSS MEɺͳͲ୲ 2
Slide 3
Slide 3 text
αʔϏεϦϥΠΞϏϦςΟάϧʔϓ is Կ • ฐࣾʹ͓͚ΔϝσΟΞͱݺΕΔΈʹଐ͢ΔαʔϏεͷ ʮΠϯϑϥʯͳͲΛԣஅతʹݟ͍ͯΔ৫ (AbemaTVͱͦͷؔ࿈Λআ) యܕతͳΠϯϑϥͰͳ͍ SREͱDevOpsͱCREͬΆׂ͍Ռ͍ͨͯ͠Δ (ৄࡉͪ͜Β) 3
Slide 4
Slide 4 text
αʔϏεϦϥΠΞϏϦςΟάϧʔϓ is Կॲ 4
Slide 5
Slide 5 text
ࠓ͢͜ͱ • λοϓϧੜͷҠઃޠ 2ؒҎ্ʹΘͨΔετʔϦʔ • લ: ྺ࢙తܦҢɺҠઃ͋Δ͋Δ • ޙ: ECS EC2/FargateͷҠઃͱ͔ΑΓσΟʔϓͳ ऴ൫ʹ࠷ۙग़ͨ৽ػೳΛࢼͯ͠Έͨ͋ΔΑ 5
Slide 6
Slide 6 text
࣍ 1. αʔϏε֓ཁ 2. ྺ࢙తܦҢ ΦϯϓϨߏ Ҡઃܭը Ҡઃ࣮ߦ 3. ʁʁʁ 4. ʁʁʁ ʁʁʁ ʁʁʁ 5. ॴײ 6
Slide 7
Slide 7 text
λοϓϧੜ αʔϏε֓ཁ
Slide 8
Slide 8 text
No content
Slide 9
Slide 9 text
λοϓϧੜ is Կ • झຯͰͭͳ͕Δ࿀׆αʔϏε • ձһ400ສਓҎ্ɺϚονϯάԆ1ԯ2,000ສ • ࠃ࠷େن 9
Slide 10
Slide 10 text
https://tapple.me 10
Slide 11
Slide 11 text
ྺ࢙తܦҢ
Slide 12
Slide 12 text
࣍ 1. αʔϏε֓ཁ 2. ྺ࢙తܦҢ ΦϯϓϨߏ Ҡઃܭը Ҡઃ࣮ߦ 3. ʁʁʁ 4. ʁʁʁ ʁʁʁ ʁʁʁ 5. ॴײ 12
Slide 13
Slide 13 text
ΦϯϓϨ࣌ͷߏ֓ཁ • Φϯϓr…ϓϥΠϕʔτΫϥυ • GitHubͰίʔυཧɺJenkinsͰϏϧυˍσϓϩΠ • αʔόͷϓϩϏδϣχϯάAnsible • Node.js + MongoDB + Elasticsearch • ϩάपΓɺFluentd tail -> aggregator -> in-house analyticsج൫ 13
Slide 14
Slide 14 text
14
Slide 15
Slide 15 text
ΦϯϓϨߏʹ͓͚Δ՝ • ύϒϦοΫΫϥυͰ͍͏ͱ͜ΖͷManagedͳαʔϏε͕গͳ͍ ΄ͱΜͲͷίϯϙʔωϯτࣗͨͪͰཧ͠ͳ͚ΕͳΒͳ͍ͨΊɺཧίετߴ • ΦʔτεέʔϦϯάɺ૬࡞Γࠐ·ͳ͍ͱ࣮ݱ͕͍͠ ίετ࠷దԽ͕Ͱ͖ͣɺৗʹ࠷େΩϟύγςΟ͕ىಈ͍ͯͯ͠ແବ ͦͯ͠࠷େΩϟύγςΟ͕มΘΕ…खಈ૿ઃ… • ࣗಈԽ͕͘͠ɺϗετোͳͲ͕ى͖ΔͨͼʹखಈΦϖൃੜ • ϓϥΠϕʔτΫϥυͷӡ༻ϧʔϧ্ɺϦʔδϣϯʹEOL͕͋ΓҠઃൃੜ ͍࣌ͬͯͨϦʔδϣϯͷEOL͕͍͖͍ۙͮͯͯͨ Disclaimer: ผʹϓϥΠϕʔτΫϥυΛdisͬͯΔΘ͚͡Όͳ͍͔Βצҧ͍͠ͳ͍ͰΑͶͬ 15
Slide 16
Slide 16 text
AWSʹҠઃ͢Δ͜ͱʹͳͬͨཧ༝ • ͳͥύϒϦοΫΫϥυ ΦʔτεέʔϦϯά͍ͨ͠ ϚωʔδυαʔϏεͰཧɾӡ༻ίετԼ͛ͯ։ൃʹूத͍ͨ͠ • ͳͥAWS ϚονϯάαʔϏεͷதͰ͢ͰʹAWSͷར༻࣮͕͋ͬͨ ϚονϯάαʔϏεΛAWSʹἧ͍͍ͨͱ͍͏͍ ϝσΟΞͷதͰAWSͷݟ͕ଟ͔ͬͨ ࣌།Ұ౦ژϦʔδϣϯΛఏڙ͍ͯͨ͠ 16
Slide 17
Slide 17 text
ҠઃܭըΛ ཱͯΑ͏
Slide 18
Slide 18 text
࣍ 1. αʔϏε֓ཁ 2. ྺ࢙తܦҢ ΦϯϓϨߏ Ҡઃܭը Ҡઃ࣮ߦ 3. ʁʁʁ 4. ʁʁʁ ʁʁʁ ʁʁʁ 5. ॴײ 18
Slide 19
Slide 19 text
Ҡઃޙͷߏ v.1: EC2 • ΞϓϦͦͷ·· Ծαʔό EC2 Πϯελϯεͱ͍͚ͯ࣋ͬͯͩ͘͠ • MongoDBͱElasticsearchͦͷ··͍࣋ͬͯ͘ MongoDBͷΞΫηεɺ֤ΞϓϦαʔόʹ͍ͬͯΔmongosΛϓϩΩγʹ͏ ElasticsearchɺALBͰΞΫηεΛࢄ • RedisɺMySQLElastiCacheɺAuroraʹ • nginxΛALBʹϦϓϨΠε • ੩తίϯςϯπͷ৴ɺS3+CloudFront 19
Slide 20
Slide 20 text
20
Slide 21
Slide 21 text
ҠઃϩʔυϚοϓ 1. σʔλϝϯςΛೖΕͨঢ়ଶͰҠઃ͠ɺͦΕҎ֎ΦϯϥΠϯͰҠઃ σʔλͷҠઃͷͨΊͷϝϯςਖ਼͍͠அɺঝͨؔ͠ऀ֤Ґʹѹతײँ ϓϥΠϕʔτΫϥυ͔ΒσʔλͷΞΫηεɺઐ༻ճઢܦ༝ 2. ΞϓϦɺݕূ͠ͳ͕ΒঃʑʹҠઃ͍ͯ͘͠ 21
Slide 22
Slide 22 text
࣮ߦ ͢Δͧ
Slide 23
Slide 23 text
࣍ 1. αʔϏε֓ཁ 2. ྺ࢙తܦҢ ΦϯϓϨߏ Ҡઃܭը Ҡઃ࣮ߦ 3. ʁʁʁ 4. ʁʁʁ ʁʁʁ ʁʁʁ 5. ॴײ 23
Slide 24
Slide 24 text
εςοϓ2: ΞϓϦͷҠઃ…ʁ • EC2 AutoscalingͷͨΊͷɺAMIϏϧυ༻Packer࡞ΓࠐΈɺݕূΛ… ͢Δ…ͭΓ…͕ͩͬͨ… Ω < ͔ͤͬ͘ͷҠઃͳΒɺΞʔΩςΫνϟมߋ͍ͨ͠Ͷͬ Ω < ϚΠΫϩαʔϏεԽͰ͖ͨΒϦϦʔεͷ୯ҐΛখ͘͞Ͱ͖Δ͠Γ͠ͱָ͔ͩ͠ Ω < Dockerfile࡞ͬͨͧ Ω < KubernetesͰͱΓ͋͑ͣಈ͍ͨͧ Ω < KubernetesͰߦ͜͏ͥ Ω < ͔ͤͬͩ͘͠ଞվળ͍ͯ͜͠͏ Μɺɺ͋Δ͐ʁɹҰ୴EC2Ͱߦ͘Μ͡Όͳ͔͚ͬͨͬ 24
Slide 25
Slide 25 text
Ҡઃޙͷߏ v.2: Kubernetes • σʔλมΘΒͣ • NLBΛIngestͱͯ͠༻ • kops + helm • ap-northeast-1 3 AZ (a/c/d) • ASGͰworkerϊʔυΛཧɺΦʔτεέʔϦϯά 25
Slide 26
Slide 26 text
26
Slide 27
Slide 27 text
Ҡઃޙͷߏ v.2: ϩάपΓ • APIαʔϏεͳͲͰ૬Γfluentdίϯςφఆٛ • ڞ༗volume͔Βtail Kinesis Lambda in-houseͳanalytics KinesisͰόοϑΝϦϯάɺin-houseͳج൫͕ࢮΜͰ͍ͯɺ ʮKinesis Lambdaʯͷ෦Ͱ͍͍ײ͡ʹϦτϥΠ͞ΕΔ ৄࡉ: KinesisͱLambdaͰͭ͘ΔServerlessͳϩάج൫ @ AWS DevDay Tokyo 2019 27
Slide 28
Slide 28 text
28
Slide 29
Slide 29 text
… Ω < ΫϥελͱVPCͱαϒωοτपΓ࡞ͬͨͧ Ω < manifestΧΩΧΩͯ͠Δͧ Ω < Α͘ݟͨΒͪΌΜͱಈ͍ͯͳ͍ͳ Ω < Kubernetesͷόά͔ͳ Ω < Dockerͷόά͔ͳ Ω < ͋ΕΕ 29
Slide 30
Slide 30 text
Ҡઃ͕ྃ͠ͳ͍ ··1͕ܦͭ
Slide 31
Slide 31 text
ͦͯ࣌͠ݶര͕ େരൃ
Slide 32
Slide 32 text
࣌ݶര #ͱ • ࣌ݶര = ઐ༻ճઢ • ϙΠϯτ: 1. σʔλͷΞΫηε͕ΫϥυΛލ͍Ͱ͍ͨ 2. ઐ༻ճઢ͕อূͳ͠Ͱఏڙ͞Ε͍ͯͨ (࣌ SLA ͕ఏڙ͞Ε͍ͯͳ͔ͬͨ) • Ҡઃ͕ྃ͠ͳ͍ঢ়ଶͰ1͕ܦͬͨ • ͦͯ͠ࣄ͕݅ى͖ͨ 32
Slide 33
Slide 33 text
࣌ݶരେരൃࣄ݅ • ઐ༻ճઢͷোͰશAPIԆര૿ɺDBෛՙߴಅɺߘࢹࣦഊɺ ΞϓϦͷΤϥʔදࣔʹΑΔେྔ࠶ϩάΠϯ ϦʔνҰൃલਗ਼ࣗฏυϥ2ɺຬɺΜͩ… • શମϝϯςφϯεΛೖΕͯɺઐ༻ճઢఏڙݩʹ͍߹Θͤͭͭ͠ ༷ࢠΛݟΔ͜ͱʹ • ࡾ࣌ؒޙɺճઢ෮چɺϝϯς໌͚ 33
Slide 34
Slide 34 text
࣌ݶരେരൃࣄ݅ɺೋճ • ೋ࿈ଓͰ·ͨಉ͡ো͕ى͖Δ • ϝϯςΠϯ͔Β3࣌ؒޙɺ෮چͷݟࠐΈ͕ͳ͘ͳΓɺ ͏Ҡઃͯ͠͠·͍͍͑͡Όͳ͍͔આΛࢲ͕ޠΓʹ͍͘ • ආઌͷ४උ։࢝ • ϝϯςΠϯ͔Β5࣌ؒޙɺճઢ͕෮چɺϝϯς໌͚ • ࠓɺ5࣌ؒҎ্ͷϝϯςφϯε • ·͍ͨͭى͖Δ͔Θ͔Βͳ͍͠ා͍͔Βɺආઌͷ४උΛଓߦ • ͦͷͰ࠷ݶಈ͘ڥͷߏஙͱσϓϩΠϑϩʔͷཱ֬·Ͱྃͯ͠͠·͏ ͜ͷ͋ͱ໓͓ۤञΛҿΈ·ͨ͠ 34
Slide 35
Slide 35 text
࣍ 1. αʔϏε֓ཁ 2. ྺ࢙తܦҢ ΦϯϓϨߏ Ҡઃܭը Ҡઃ࣮ߦ 3. ʁʁʁ 4. ʁʁʁ ʁʁʁ ʁʁʁ 5. ॴײ 35
Slide 36
Slide 36 text
No content
Slide 37
Slide 37 text
࣍ 1. αʔϏε֓ཁ 2. ྺ࢙తܦҢ ΦϯϓϨߏ Ҡઃܭը Ҡઃ࣮ߦ 3. Re: ো͔Β࢝ΊΔۓٸҠઃੜ׆ 4. ͋Δ͖࢟ EC2 -> ECS (EC2 Type) ECS (EC2 Type) -> ECS (Fargate Type) 5. ॴײ 37
Slide 38
Slide 38 text
ҠઃϩʔυϚοϓ • 3ϑΣʔζͰ࣮ࢪ 1. ۓٸEC2Ҡઃ: ͱΓ͋͑ͣ ΦϯϓϨ EC2 (࣌ؒՔ͗) • ϢʔβʹͰ͖Δ͚ͩૣ͘ΑΓ҆ఆͨ͠ڥͷఏڙ͢ΔͨΊ 2. EC2 ECS (EC2 Type) 3. ECS (EC2 Type) ECS (Fargate Type) • ͙͢ʹFargateʹ͠ͳ͔ͬͨཧ༝: • Fargateͷݟ͕গͳ͔ͬͨ • ࣌Γͳ͍ػೳ͕͋ͬͨΓɺߴ͔ͬͨΓʢ࠷ֹۙʹͳͬͨΓػೳ͕૿͑ͨΓʣ • λοϓϧϝϯόʔͷࣝΛਂΊΔͨΊʹɺֶ͋͑ͯशͷͨΊEC2ʹ • FargateͱҟͳΓɺEC2Ͱdocker exec -it ͳͲͰίϯςφʹϩάΠϯͯ͠ௐࠪɺσόοά͕Ͱ͖Δ 38
Slide 39
Slide 39 text
KubernetesΛఘΊͯECSΛ࠾༻ͨ͠ཧ༝ • KubernetesͰؤுͬͯݕূ͍͕ͯͨ͠ɺ 1͔͔ͬͯ݁ہຊ൪ʹग़ͤΔϨϕϧʹࢸΒͳ͔ͬͨʢׂѪʣ • ECSͷํ͕AWSͷଞͷαʔϏεͱͷੑ͕ߴ͍ • Kubernetes͡Όͳ͍ͱ͍͚ͳ͍ϢʔεέʔεͰͳ͔ͬͨ Service MeshͷΑ͏ͳෳࡶͳߏͰͳ͘ɺಠཱͨ͠API͍͔ͭ͘ͱόον͍͔͚ͭͩ͘ • SRGͱͯ͠ฐࣾϝσΟΞࢠձࣾͱͯ͠ɺECSͷϊϋ͕ଟ͍ ࣗݾհʹ͋ΔϦϯΫࢀর ߏஙͷΈͰ4ؒ + ΦʔτεέʔϦϯάͷઃܭ 1िؒʢׂ߹มߋͱͱʹ࣮ࢪʣ 39
Slide 40
Slide 40 text
ۓٸEC2Ҡઃ: ϩʔυϚοϓ • ߏΛେ͖͘ม͑ͣɺαʔόΛͦͷ··EC2Ͱ͍࣋ͬͯ͘ QCɺෛՙࢼݧͳͲΛ௨ͯ͡Ϣʔβʹग़͍͍ͯ͜͠ͱ͕ূ໌Ͱ͖Δ·ͰΓସ͑ͳ͍ ͨͩ͠ɺ͠·ͨେো͕ى͖ͨ߹ɺ৽ڥΛආઌͱͯ͠ར༻ • ίϯςφԽߏΛߏஙɺςετ • EC2ͷΓସ͑ޙɺίϯςφԽߏʹΓସ͍͑ͯ͘ KubernetesΛఘΊͯɺECSΛ࠾༻ʢޙʹղઆʣ KubernetesݕূΛͨ͠ͱ͖ͷDockerfileVPCपΓͳͲྲྀ༻ 40
Slide 41
Slide 41 text
ۓٸEC2Ҡઃ: ߏங • Packerͱ͔Φʔτεέʔϧͱ͔Ұ୴ؾʹͤͣߏங • രͰTerraformͰEC2ܥɺηΩϡϦςΟάϧʔϓɺALBपΓΛඋʢԶʣ • AnsibleΛमਖ਼͠ͳ͕Βྲྀ͢ʢλοϓϧϝϯόʔʣ • ΞϓϦσϓϩΠɺಈ࡞֬ೝɺमਖ਼ͷ܁Γฦ͠ • ߹ܭ12࣌ؒͰͱΓ͋͑ͣಈ͘ͷ͕ • ·ͨো͕ى͖ͨΒආઌͱͯ͠͏ 41
Slide 42
Slide 42 text
ۓٸEC2Ҡઃ: ࠷ऴ֬ೝͱΓସ͑ • ߏஙͷཌ: QCɺϦάϨογϣϯςετɺෛՙࢼݧʹ߹֨ • ҰिؒΛ͔͚ͯঃʑʹϦΫΤετΛ৽͍͠ڥʹدͤΔ • tapple.me AϨίʔυΛALIASͰRoute 53 Traffic Flowʹ͚Δ • ϓϥΠϕʔτΫϥυLBͱAWS ALBͷׂ߹ΛweightͰ੍ޚ • Θ͔Γ͘͢͢ΔͨΊʹɺweightͷ߹ܭ͕100ʹͳΔΑ͏ʹઃఆ • ࣮ࡍͷΞΫηεϩάͰׂ߹Λ֬ೝ 42
Slide 43
Slide 43 text
43
Slide 44
Slide 44 text
44
Slide 45
Slide 45 text
Route 53 Traffic Flowॴײ • weightͷมߋΛద༻͔ͯ͠Βɺ࣮ࡍͷϦΫΤετͷׂ߹͕มΘΔ·Ͱ ~ 5 • DNSΩϟογϡ͕มʹӨڹ͢Δ͜ͱͳ͘ɺ ࢦఆͨ͠weightͱ࣮ࡍͷΞΫηεͷׂ߹2%΄Ͳͷޡࠩ • ΫϥυҠઃϕετϓϥΫςΟε͗͢Δ… • KibanaͰϦΞϧλΠϜͰׂ߹͕มΘΔͷΛݟΔͷָ͍͠… 45
Slide 46
Slide 46 text
2िؒͰEC2Ҡઃྃ ര
Slide 47
Slide 47 text
͋Δ͖࢟
Slide 48
Slide 48 text
࣍ 1. αʔϏε֓ཁ 2. ྺ࢙తܦҢ ΦϯϓϨߏ Ҡઃܭը Ҡઃ࣮ߦ 3. Re: ো͔Β࢝ΊΔۓٸҠઃੜ׆ 4. ͋Δ͖࢟ EC2 -> ECS (EC2 Type) ECS (EC2 Type) -> ECS (Fargate Type) 5. ॴײ 48
Slide 49
Slide 49 text
Ҡઃޙͷߏ v.3: ECS EC2 ԦಓͳECS EC2: • ALB • ECS Service (EC2 Type) ͨͩ͠ɺBatchܥશ෦Fargate (ޙʹղઆ) • EC2 Auto-Scaling Group (ΫϥελͷόοΫΤϯυ) 49
Slide 50
Slide 50 text
50
Slide 51
Slide 51 text
ECS EC2Ҡઃ: ECSΫϥελ • ECSόοΫΤϯυɺEC2 + Autoscaling Group • VanillaͳAmazon Linux (ECS-optimized) AMIͰىಈɺ user_dataͰͪΐͬͱͨ͠ॳظԽ͚࣮ͩߦ • εέʔϦϯάϝτϦοΫεɺECS ClusterͷCPUReservationͷMaximum 51
Slide 52
Slide 52 text
ECS EC2Ҡઃ: APIܥ • API༻αʔϏεEC2 Type • εέʔϦϯάϝτϦοΫεɺECS ServiceͷCPUUtilizationͷMaximum • DockerfileɺΞϓϦΛίϯςφͰಈ͔ͨ͢ΊͷͷҰࣜɺ Kubernetesݕূͷͱ͖ͷͷΛྲྀ༻ • ϚΠΫϩαʔϏεʹ͚Δͱ͜ΖҰ୴Βͳ͍ ཧ༝ɿALBΛར༻͍ͯ͠ΔͨΊɺޙ͔Βಛఆͷύε͚ͩผͷαʔϏεʹϧʔςΟϯάͤ͞Δ ͜ͱ͕Մೳɺ͙͢Δඞཁ͕ͳ͍ 52
Slide 53
Slide 53 text
ECS EC2Ҡઃ: όονܥ • όον༻αʔϏεFargate Type • ݁ߏසൟʹ࣮ߦ͞ΕΔόον͕͋ͬͯɺ EC2Ͱಈ͔͢ͱASGͷΦʔτεέʔϦϯάͷઃܭ͕໘ͳ͜ͱʹͳΔ… όον༻ͷΫϥελΛ࡞ΔͱϦιʔε͕ແବʹͳΔ͠ɺ ࡞Βͳ͍ͱεέʔϦϯάΞΫγϣϯͷढ़හੑ… • CloudWatch Eventsͷcron͕ࣜͪΐͬͱಛघͳͨΊɺ طଘͷcronࣜΛͪΐͬͱ͍͡Δඞཁ͕͋ͬͨ • Baikonur OSS fargate-scheduled-task ϞδϡʔϧΛར༻ 53
Slide 54
Slide 54 text
ECS EC2Ҡઃ: DB • MongoDBɺElasticsearchʢ΄΅ʣͦͷ·· • EC2ɺϓϥΠϕʔτΫϥυͰΠϯελϯε͝ͱʹىಈ͍ͤͯͨ͞ mongosɺઐ༻EC2 x 3ʹͨ͠ • mongos͕ݱΕͨΓফ͑ͨΓ͢Δͱɺconfig DBʹ͏͍ͳ͍mongosͷใ͕ཷ·Δ • ͢Ͱʹ͍ͳ͍mongosʹmongoc͕ping͠Α͏ͱ͍ͯ͠Δʁ • ޙʹ૿ઃ͞Ε…ͦͯ͠·ͨ૿ઃ͞Εͨ… 54
Slide 55
Slide 55 text
ECS EC2Ҡઃ: ϩάपΓ • Kubernetes༻ͷͷͱҰॹɺ૬Γfluentdίϯςφར༻ • ڞ༗volume͔Βtail aggregator Kinesis Lambda in-houseͳanalytics KinesisసૹϓϥάΠϯͱϩάʹର͢Δཁ݅ͷ߹Ͱ࠷ऴతʹfluentd aggregatorḉര 55
Slide 56
Slide 56 text
ECS EC2Ҡઃ: Cluster ASGͷεέʔϦϯάઃܭ • ΦʔτεέʔϦϯάͱ͍͏֓೦͕ECSҠઃ·Ͱଘࡏ͠ͳ͔ͬͨ • Ұ୴ɺෛՙͷ͔͔Γํ͕ࣅ͍ͯΔαʔϏεͷᮢΛύΫͬͨ • 1िׂ͔͚ؒͯ߹Λมߋ͢ΔΞϨͱಉ࣌ʹɺ εέʔϦϯάΛݟकΓͭͭࡉ͔͍ௐΛߦͳͬͨ • εέʔϦϯάͷௐΛߦͳͬͨࡍͷߟ͑ํΛ͝հ 56
Slide 57
Slide 57 text
ECS EC2Ҡઃ: Cluster ASGͷεέʔϦϯάઃܭ • CPUReservationͷAverage͕75%-85%ͷؒΛӭ͙Α͏ʹɺ Step ScalingΛखͰௐ εύΠΫɺϐʔΫΛܴ͑Δͱ͖ʹɺΫϥελͷΩϟύ͕ TaskͷஔͷΛҾͬுΒͳ͍Α͏ʹஸೡʹௐ 57
Slide 58
Slide 58 text
Step ScalingɺͩΔ͍Ͱ͠ΐʁ • ઃܭ͕ͩΔ͍͍͠͠ • ͦͯ͠ରࡦΛ͠ͳ͍ͱASG scale-in࣌ʹੜ͖͍ͯΔίϯςφ͕ࡴ͞ΕΔ • ରࡦ: EC2 Auto-ScalingͰECSΜͰ·͔͢ʁΤϥʔϨʔτߴ͍Ͱ͔͢ʁٹ͍͍ͬͯ͋͛ͯͰ͔͢ʁ • ECS Cluster Auto Scalingͱ͍͏ਆػೳ͕Ͱͨʂ • ͍͍ײ͡ʹεέʔϦϯάͯ͘͠ΕΔɺStep Scaling͢Δඞཁͳ͠ • CPUɺϝϞϦɺENIͳͲɺ͍ͣΕ͔ҰͭͷΩϟύγςΟͷछྨͰͳ͘ɺ ্ཱ͍ͪ͛ͨTask͕࣮ࡍ্ཱͪ͛ΒΕΔͷ͔ͱ͍͏γϛϡϨʔγϣϯͰΩϟύෆΛಛఆ • ىಈ͍ͯ͠Δίϯςφͷ͋ΔEC2Λࡴ͞ͳ͍ઃఆͰ͖ΔɺൿͷλϨͳ͠Ͱಈ͘ʂ • ࣌ͳ͔ͬͨͷͰͱͯͭΒ͔ͬͨɺECSͷதͷਓ·ͫ͋Γ͕ͱ❤ 58
Slide 59
Slide 59 text
ECS EC2Ҡઃ: ECS ServiceͷεέʔϦϯάઃܭ • CPUUtilizationͷMaximum͕40%-75%ͷؒΛӭ͙Α͏ʹɺ Step ScalingΛखͰௐɺ֤ίϯςφͷෛՙΛ֬ೝ ͜Ε͙Β͍ͷઃఆͰɺ֤ίϯςφ͕݈શతͳෛՙ (~50%) Λड͚Δ ίεύͱϨΠςϯγͷόϥϯγϯά 59
Slide 60
Slide 60 text
Step ScalingɺͩΔ͍Ͱ͠ΐʁ • ઃܭ͕ͩΔ͍͍͠͠ • Target Tracking Scaling (for ECS)ͱ͍͏ͷ͕ग़ͨ • ʮCPU༻͕ฏۉͰ60%͙Β͍ʹͳΔΑ͏ʹͯ͠ɺϤϩʯͱ͍͏ઃఆ͚ͩͰ ͋ͱΑΖͬͯ͘͘͠ΕΔ • ੍͕࣌͋ͬͯಋೖ͕͔ͬͨ͠ • ͑ΔϝτϦΫε͕ݶΒΕ͍ͯͨ…هԱ • ޙʹෛՙࢼݧڥͰࢼ͢ɺզʑͷϢʔεέʔεʹ߹Θͣ • Step Scaling͔Β͍·ͩʹಀ͛ΒΕ͍ͯͳ͍ 60
Slide 61
Slide 61 text
ECS EC2Ҡઃ: ECS ServiceͷεέʔϦϯάઃܭ 61 ίϯςφͷCPU༻͕40-60% ͙Β͍ʹͳ݈ͬͯͯ߁తͳෛՙ
Slide 62
Slide 62 text
ECS EC2Ҡઃ: ࠷ऴ֬ೝͱΓସ͑ • ۓٸEC2ҠઃͱҰॹͩΑ • QCɺϦάϨογϣϯςετɺෛՙࢼݧʹ߹֨͢Δ·Ͱमਖ਼࣮ࢪ • ҰिؒΛ͔͚ͯঃʑʹϦΫΤετΛدͤΔ • tapple.me AϨίʔυΛALIASͰRoute 53 Traffic Flowʹ͚Δ • EC2ڥͷALBͱECSڥͷALBͷׂ߹ΛweightͰ੍ޚ • Θ͔Γ͘͢͢ΔͨΊʹɺweightͷ߹ܭ͕100ʹͳΔΑ͏ʹઃఆ • ࣮ࡍͷΞΫηεϩάͰׂ߹Λ֬ೝ 62
Slide 63
Slide 63 text
ECS EC2Ҡઃ: Ҡઃޙͷ͋Ε͜Ε • ઐ༻ճઢ͕ͳ͘ͳͬͨ͜ͱͰɺAWSྉ͕͔ۚͳΓ҆͘ͳͬͨ • ϦΫΤετΛฦͨ͢Ίͷ௨৴AWS௨৴ͷΈʹͳͬͯɺ API͕രʹͳͬͨ ࣮ͱͱͱͯ༏लͩͬͨ ϨΠςϯγ͕ฏۉͰ120ms͘ͳΓɺmsೋܻ 63
Slide 64
Slide 64 text
࣍ 1. αʔϏε֓ཁ 2. ྺ࢙తܦҢ ΦϯϓϨߏ Ҡઃܭը Ҡઃ࣮ߦ 3. Re: ো͔Β࢝ΊΔۓٸҠઃੜ׆ 4. ۓٸҠઃ͔Β͋Δ͖࢟ EC2 -> ECS (EC2 Type) ECS (EC2 Type) -> ECS (Fargate Type) 5. ॴײ 64
Slide 65
Slide 65 text
No content
Slide 66
Slide 66 text
Fargate! • ECS EC2Ҡઃ͔Β΄΅1͕ܦͬͨ • EC2ʹϩάΠϯͯ͠docker execͱ͔͢Δ͜ͱ͕΄΅ͳ͘ͳͬͯ ΞϓϦέʔγϣϯίϯςφʹదͨ͠ܗʹ͍͖ۙͮͯͨ • ϝϯόʔECSɺίϯςφΛͬͨΞϓϦέʔγϣϯͷӡ༻ʹ׳Ε͖ͯͨ • ͦͯ͠ECS EC2ʹର͢Δෆຬ͕ཷ·͖ͬͯͨ • EC2 ASGͷεέʔϧΛͨͳ͚ΕͳΒͳ͍ɺͦͷͨΊεέʔϦϯάɺσϓϩΠ͕͍ • ΩϟϯϖʔϯΛ࣮ࢪ͢Δࡍʹscheduled scaling͕ඞཁɺͦͷϙϦγʔΛઃܭɾܭࢉ͢Δͷେม • AMIߋ৽͢ΔͨͼʹASGͷEC2ΠϯελϯεΛస͕͢ͷ͕େม • Α͠ɺFargateԽ͠Α͏ʂ 66 ࢲ࠷ॳ͔Βɺ࠷ऴతʹFargateʹ͢ΔͭΓͩͬͨ
Slide 67
Slide 67 text
67
Slide 68
Slide 68 text
Fargateͷίετʹؔͯ͠ • ϦιʔείετOn-demand EC2 (RIͳͲͷׂҾͳ͠) ͱൺֱͯ͠ Ή͠Ζ҆͘ͳΔ • EC2ͷόοΫΤϯυΠϯελϯεΛASGͱ͔Ͱ༻ҙ͢ΔࡍʹɺCPU/ϝϞϦͷۭ͖͕ৗʹ 15-20%ʹͳΔΑ͏ʹ͍ͯ͠Δ͔Βʢεέʔϧͷढ़හੑʣ • ֹͦͯ͠ʹԼ͛͞ΕͨΓͨ͠ • ͞ΒʹɺEC2ϨΠϠͷΦϖϨʔγϣϯɾཧίετ͕ݮ • ηΩϡϦςΟύονɺDockerͷύον࡞ۀ͞Α͏ͳΒ • ͍҆͠ɺ͍͍͡ΌΜ 68
Slide 69
Slide 69 text
FargateͷΠΠͱ͜Ζ • FirecrackerͷొͰىಈ͕͘ͳͬͨ • ENIͷallocationಛʹੲͱൺͯ͘ͳ͍ͬͯΔ • EC2ͷΩϟύͭඞཁͳ͍͠ɺىಈ͍ͷͰσϓϩΠɺΓ͠ɺεέʔϦϯάͷߴԽ • EC2Ͱͷ՝: bridge network͕͍͕ɺhostΛ͏ͱϙʔτ͕େมͳ͜ͱʹ ͳΔ͔ΒawsvpcΛݕ౼͕ͨ͠ɺΠϯελϯελΠϓͱαΠζ͋ͨΓͷENI ༩্ݶ͕ͱͯগͳ͍ • ࠷ۙENI TrunkingͰ؇͞Ε͍ͯΔ͕ͦΕͰΓͳ͔ͬͨ • FargateΛ͏ͱ͖awsvpc͔͑͠ͳ͍͕ɺͦΕͰ͍͍ • Docker LinksͬͯΔϚφʔͷΑΖ͘͠ͳ͍TaskɺFargateԽ (+awsvpcԽ) Ͱͳͤ͘Δ 69
Slide 70
Slide 70 text
Fargateͷͪΐͬͱ໘ͳͱ͜Ζ • TaskͷCPUͱϝϞϦΛܾΊΒΕͨΈ߹Θͤͷத͔Βબͳ͍ͱμϝ • Έ߹Θͤଟ͍͠෯͘ઃఆͰ͖Δ͕ࣗͷχʔζʹtailoredͳͪΐ͏Ͳ͍͍Ωϟύʹ ͳΒͳ͍ • AWS͞Μ͕ΫϥελΛཧͯ͘͠ΕͯΔ͠ɺڐͤΔ • Docker VolumeͰͷϑΝΠϧڞ༗ɺ1 volumeͰhard limit 4GB 70
Slide 71
Slide 71 text
͍ͭͰʹΔ͜ͱʹͳͬͨ͜ͱ • ͔ͤͬ͘ServiceɺALBΛ࡞Γ͔͢ΒΓ͍ͨͳͱࢥͬͨ͜ͱ • ALB Least Outstanding RequestsΞϧΰϦζϜͷݕূ • Internal LB༻ͷtarget groupΛServiceʹඥ͚Δ • Internal/Global༻ͷTGΛҰͭͷServiceʹඥ͚ • લෳTGͷඥ͚͕Ͱ͖ͳ͔ͬͨͨΊInternalઐ༻Service… 71
Slide 72
Slide 72 text
ALB Least Outstanding Requests Ͳ͕ͬͪRound-RobinͰͲ͕ͬͪLORͩͱࢥ͍·͔͢ʁ 72
Slide 73
Slide 73 text
ALB Least Outstanding Requests ਖ਼ղɿ Round-Robin LOR ͙͢͢͜ͱʹͳͬͨ 73
Slide 74
Slide 74 text
εέʔϦϯάपΓͷௐ • Datadog APMͷϨΠςϯγɺFargateͷCPU༻͕ಉఔʹͳΔΑ͏ௐ • APMͰͷEC2/FargateͷผDD_ENV • DatadogϝτϦΫε໊લۭؒ(docker.* vs ecs.*)ͱTask Family໊ • ϩάɺplatform = {“ec2”, “fargate”} ͱ͍͏ϑΟʔϧυՃ ո͍͠ ո͍͠ چڥಉ༷ Ϥγʂ چڥϨΠςϯγ ৽ڥϨΠςϯγ 74
Slide 75
Slide 75 text
ׂΓ߹͍มߋͷ֬ೝ on Kibana • platform = {“ec2”, “fargate”} ͳϑΟʔϧυͰ ΞΫηεϩά͔ΒϦΞϧλΠϜͰՄࢹԽ 75
Slide 76
Slide 76 text
ׂ߹Λ֬ೝɺϤγʂ Τϥʔ֬ೝɺϤγʂ 76
Slide 77
Slide 77 text
LORΓ͠ Ϥγʂ ϨΠςϯγ Ϥγʂ ΤϥʔϨʔτ Ϥγʂ εέʔϦϯά Ϥγʂ 77
Slide 78
Slide 78 text
Ҡઃྃ
Slide 79
Slide 79 text
λοϓϧͷΠϯϑϥपΓͷ͜Ε͔Β • Fargate SpotΛͬͨover-provisioningͰٸͳεύΠΫʹରԠ • FireLens + KinesisͳϩάपΓ • FireLens΄Μͱ͍͢͝ΑɺϩάपΓͷ՝(container nativeͳܗͰ)େͳΜͱ͔ͳΔ • ͨͩ͠ɺloggingDriverࢦఆʹͳΔͷͰCloudWatch LogsʹFireLensʹྲྀ͢ͷ͍͠ • ࠓޙ͜Ε͕վળ͞ΕΔ͜ͱΛفΓͳ͕ΒFeature Request͛ ʢͬ'-')‸ = ͟ ͟͞͞ŲƄőƃɹ • ΧελϜεέʔϦϯά • CPUͰͳ͘ΞΫηεɺͳͲͰΠΠײ͡ͰŧŔŕŰƅźͳεέʔϥΛ࡞͍ͬͯΔ • ϝτϦΫεΛͨͣʹ1ະຬͷϦΫΤετมԽʹରԠ͠ϨΠςϯγΛ͞Βʹ҆ఆԽ • @pahudnet ͞ΜͷŧŔŕŰƅźεέʔϥΛࢀߟʹͭͭ͠ • ΧελϜσϓϩΠ Deployment Controller: EXTERNALͰTask Set APIΛͬͨߴͳαϜγϯάΛ࡞͍ͬͯΔ 79
Slide 80
Slide 80 text
࣍ 1. αʔϏε֓ཁ 2. ྺ࢙తܦҢ ΦϯϓϨߏ Ҡઃܭը Ҡઃ࣮ߦ 3. Re: ো͔Β࢝ΊΔۓٸҠઃੜ׆ 4. ۓٸҠઃ͔Β͋Δ͖࢟ EC2 -> ECS (EC2 Type) ECS (EC2 Type) -> ECS (Fargate Type) 5. ॴײ 80
Slide 81
Slide 81 text
ॴײ • ॊೈͰ͋Ε • ॳͷతΛΕΔͳ • ϩʔυϚοϓΛҾ͘͜ͱ͕େࣄ • ເΛݟΔ͜ͱѱ͍͜ͱ͡Όͳ͍͕ɺΔ͖͜ͱ͔ͬ͠Γɺ ॱ൪ʹ͍ͬͯ͘͠ • Ϣʔβͷ͜ͱΛߟ͑ͳ͕ΒɺϢʔβମݧΛ࠷༏ઌʹͯ͠ࣄʹऔΓΉ͠ • ECS͍͍ͧʢAWS Managedͱͷੑͱֶशۂઢʣ • Fargate͍͍ͧʢόοΫΤϯυͷ͜ͱΛΕͯαʔόϨεʹಀ͍͛ͨਓੜʣ 81
Slide 82
Slide 82 text
એ 82 ← https://baikonur.dev ʹԿ͔Λग़͠·ͨ͠
Slide 83
Slide 83 text
बۀܕΠϯλʔϯγοϓɺ௨ืूதʂ • ΤϯτϦʔక: Πϯλʔϯγοϓ։݄࢝ͷ3ϲ݄લͷ݄ • ৄࡉ: https://www.cyberagent.co.jp/careers/students/event/detail/id=24422 83
Slide 84
Slide 84 text
࠷ޙʹ͏Ұճʂ
Slide 85
Slide 85 text
85 ͜ΕΛ
Slide 86
Slide 86 text
86 ͜͏ͯ͠
Slide 87
Slide 87 text
87 ͜͏ͯ͠
Slide 88
Slide 88 text
88 ͜͏͡Όʂ
Slide 89
Slide 89 text
͝ਗ਼ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠