Slide 1

Slide 1 text

Amazon ECSͰ޷͖ͳ͚ͩݕূ؀ڥ ΛىಈͰ͖Δ OSSͷઃܭɾ࣮૷ɾӡ༻ YAPC::Hiroshima 2024 @fujiwara ౻ݪढ़Ұ࿠

Slide 2

Slide 2 text

ࣗݾ঺հ @fujiwara ໘ന๏ਓΧϠοΫSREνʔϜ ISUCON 1,2,5,11 ! ༏উ4ճ ISUCON 3,8,12,13 ӡӦ(ग़୊) 4ճ github.com/kayac/ecspresso Amazon ECS σϓϩΠπʔϧ github.com/fujiwara/lambroll AWS Lambda σϓϩΠπʔϧ

Slide 3

Slide 3 text

Agenda ϒϥϯνผ։ൃɾݕূ؀ڥͷ࣮ݱํ๏ͱ՝୊ ݕূ؀ڥΛ༰қʹىಈͰ͖ΔOSS mirage-ecs mirage-ecsͷઃܭͱ࣮૷ mirage-ecsͷ࣮ફతͳӡ༻

Slide 4

Slide 4 text

ϒϥϯνผ։ൃɾݕূ؀ڥͷ࣮ݱํ๏ͱ՝୊

Slide 5

Slide 5 text

ʮϒϥϯνผ։ൃɾݕূ؀ڥʯ (͜͜Ͱͷఆٛ) ʮWebαʔϏεͷαʔόʔΛ೚ҙͷ(ϦϙδτϦͷϒϥϯνͷ)ঢ়ଶͰىಈ ͯ͠ɺಠཱͨ͠URLͰ֎෦͔ΒΞΫηεͰ͖ΔΑ͏ʹͨ͠΋ͷʯ

Slide 6

Slide 6 text

ʮϒϥϯνผ։ൃɾݕূ؀ڥʯ͕ඞཁͳ৔໘ ΤϯδχΞ͸ϩʔΧϧͰ։ൃ؀ڥΛىಈͰ͖Δɺ͕ ͦΕҎ֎ͷਓ΋։ൃதͷαʔόʔʹΞΫηε͍ͨ͜͠ͱ͸ଟ͍ νʔϜ֎ͷਓʹ։ൃதͷঢ়ଶΛݟͯ΋Β͍͍ͨ - ͓٬͞Μͱ͔ؔ܎ऀ ෳ਺ਓͰಉ͡؀ڥʹಉ࣌ʹΞΫηε͍ͨ͠ - ήʔϜͩͱνʔϜνΣοΫͱ͍͏จԽ͕͋Δ - ෳ਺ਓͰΞΫηε͠ͳ͍ͱ੒ཱ͠ͳ͍ΞϓϦέʔγϣϯ

Slide 7

Slide 7 text

ʮϒϥϯνผ։ൃɾݕূ؀ڥʯ͕ඞཁͳ৔໘ ΤϯδχΞҎ֎Ͱ΋ࣗ෼ઐ༻ͷαʔόʔ͕΄͍͠ - ςετɺQAͷͨΊ - σβΠφʔ͕ը૾΍ΞηοτΛ࣮ػ֬ೝ͢ΔͨΊ - σΟϨΫλʔ͕Ϛελʔσʔλ΍͓஌ΒͤͳͲΛ֬ೝ͢ΔͨΊ ؀ڥͷىಈɺఀࢭ͸୭Ͱ΋Ͱ͖ΔΑ͏ʹͳ͍ͬͯͯ΄͍͠ ʮXXX؀ڥΛىಈ͓ئ͍͠·͢ʂʯʮߋ৽͓ئ͍͠·͢ʂʯ… ΤϯδχΞ͕͍͍ͪͪରԠ͍ͯͨ͠Βେม

Slide 8

Slide 8 text

࣮ݱํ๏(1) ʮࣄલʹෳ਺؀ڥΛ࡞੒ͯ͠࢖͍ճ͢ʯ ͋Β͔͡Ίɺ؀ڥΛෳ਺༻ҙ͓ͯ͘͠ ؀ڥ͸೚ҙͷϒϥϯνʹ੾Γସ͑ͯىಈͰ͖ ΔΑ͏ʹ͓ͯ͘͠ ࢖͍͍ͨਓ͕ۭ͍͍ͯΔ؀ڥΛ ೚ҙͷϒϥϯνͰىಈͯ͠࢖͏ ໰୊఺ - ୭͕Ͳ͜Λ࢖͍ͬͯΔ͔Λ؅ཧ͢Δඞཁ - ࢖͍ऴΘͬͨΒ଎΍͔ʹ։์͠ͳ͍ͱଞͷਓ ͕࢖͑ͳ͍ - ͔ͱ͍ͬͯશһ෼༻ҙ͢Δͱߴίετ

Slide 9

Slide 9 text

࣮ݱํ๏(2) ʮඞཁͳ࣌ʹIaCͰશ෦࡞Δʯ ࢖͍͍ͨλΠϛϯάͰඞཁͳαʔόʔϦιʔεΛҰࣜ·Δͬͱ࡞੒ ྫ: AWSͰALB + ECS + RDS + Elas0Cache ALB, ECSαʔϏε/λεΫ, RDS, ElastCache Λ࡞੒Ͱ͖Δίʔυ (Terraformͱ͔CFnͱ͔CDKͱ͔)Λ࡞͓͍ͬͯͯόʔϯ

Slide 10

Slide 10 text

ʮඞཁͳ࣌ʹIaCͰશ෦࡞Δʯ ํ๏ͷ໰୊఺ ࡞Δͷʹֻ͕͔࣌ؒΔ(΍͕ͭ͋Δ) - ৽نͷRDS΍Elas*CacheΛىಈ͢Δͱ20෼ʙͱ͔ Ұؙࣜ͝ͱ༻ҙ͢Δͱͱʹֻ͔͓͕͔ۚ͘Δ - ফ͠๨ΕΔͱ… ! ڞ༻Ϧιʔεͱಈతͳ࡞੒/࡟আͱIaCͷ૬ੑ͕ඍົ(ͳ͜ͱ͕͋Δ) - ίετ࡟ݮͷͨΊʹҰ෦ͷϦιʔε(LBͳͲ)Λڞ༻͢Δͱى͖͕ͪ - ؀ڥAͷ࡞੒ͱBͷ࡟আ͸ฏߦͰͰ͖ͳ͍ɺͱ͔

Slide 11

Slide 11 text

ํ๏(1)(2)ͷ໰୊఺ ͋Β͔͡Ί༻ҙ͓ͯ͘͠ͱऔΓ߹͍ʹ(؅ཧίετ) ଍Γͳ͍ͱ଴͕ͪ࣌ؒແବʹ(࣌ؒ) શһ෼Λৗʹ༻ҙ͢Δͱֻ͓͕͔ۚΔ(Πϯϑϥίετ) ىಈͱఀࢭʹֻ͕͔࣌ؒΔͱ଴͕ͪ࣌ؒແବ(࣌ؒ) ֻ͕͔࣌ؒΔͱख์ͨ͘͠ͳ͘ͳΔ(ෆ଍ɾ์ஔ→Πϯϑϥίετ) ͍ͭͰ΋ඞཁͳ͚ͩɺߴ଎ʹىಈͰ͖ͯ௿ίετͳ࢓૊Έ͕΄͍͠

Slide 12

Slide 12 text

͍ͭͰ΋ඞཁͳ͚ͩ ߴ଎ʹىಈͰ͖ͯ ͔͠΋௿ίετ Λ࣮ݱ͢Δ

Slide 13

Slide 13 text

mirage-ecs ʮϒϥϯνผ։ൃɾݕূ؀ڥʯΛߴ଎ʹىಈͰ͖Δ ௿ίετͰ࣮ݱ͢Διϑτ΢ΣΞ(OSS) github.com/acidlemon/mirage-ecs mirage-ecs is a reverse proxy for ECS tasks and a manager for the tasks. ECSλεΫͷϚωʔδϟʔ݉ϦόʔεϓϩΩγ

Slide 14

Slide 14 text

Demo

Slide 15

Slide 15 text

֓೦ਤ ALBʹ *.example.com ΛׂΓ౰ͯΔ mirage-ecsʹશͯͷϦΫΤετΛసૹ - foo.example.com ͸؀ڥ foo ʹproxy - bar.example.com ͸؀ڥ bar ʹproxy mirage.example.com Ͱ WebUI / API Λఏ ڙ - ؀ڥىಈ → ECS RunTask - ؀ڥ࡟আ → ECS StopTask mirage-ecs ͱ͸ 1.ʮ؀ڥʯΛ ECS ͷλεΫͱͯ͠ىಈ/ఀࢭ 2.ʮ؀ڥʯ΁ͷϦΫΤετΛλεΫʹ Reverse Proxy͢Διϑτ΢ΣΞ

Slide 16

Slide 16 text

mirage-ecsΛ࢖͏ͱͳʹ͕خ͍͔͠ ࢖͍͍ͨ؀ڥΛԿݸͰ΋ɺ͙͢ʹ༻ҙͰ͖Δ - ECSλεΫΛFargateͰىಈ͢Ε͹͍ͭ͘Ͱ΋ - ىಈ࣌ؒ͸࠷୹1෼ʙ௕ͯ͘΋10෼ఔ౓ ௿ίετ - 1؀ڥ = ECSλεΫ1ݸ(1ʙ2vCPU, Memory 4GBʙ) - ECS on EC2Ͱಈ͔͢͜ͱ΋Մೳ ؀ڥͷىಈ࡟আ͕WebUIͱAPIͰૢ࡞Ͱ͖Δ - WebUI: ඇΤϯδχΞʹ΋༏͍͠ - API: ىಈ/࡟আΛSlack botͳͲͰ࣮૷Ͱ͖Δ

Slide 17

Slide 17 text

ChatOpsͷྫ

Slide 18

Slide 18 text

WebΞϓϦέʔγϣϯΛmirage-ecsͰىಈ͢Δ ඞཁͳ΋ͷͱϦϙδτϦ͕ೖͬͨΠϝʔδͱECSλεΫఆٛΛ༻ҙ - GitϦϙδτϦΛΠϝʔδʹম͖ࠐΜͰ͓͘(େ͖ͳϦϙδτϦͷ৔߹) - খ͍͞৔߹͸ىಈ࣌ʹશ෦cloneͯ͠΋Α͍ mirage-ecs͕ఆٛ͢Δ؀ڥม਺ ىಈ࣌ʹ؀ڥ໊ͱϒϥϯνΛࢦఆ͢Δͱɺ؀ڥม਺Λઃఆ͢Δ - SUBDOMAIN : ؀ڥ໊ fujiwara, event-111, ……ͳͲαϒυϝΠϯ - GIT_BRANCH : main, feature/some-x, …… Gitͷϒϥϯν໊ - ΄͔ʹ΋ઃఆͰ೚ҙͷ؀ڥม਺ΛఆٛͰ͖Δ ↑ WebUI/API͔Βىಈ࣌ʹࢦఆՄೳ

Slide 19

Slide 19 text

WebΞϓϦέʔγϣϯΛmirage-ecsͰىಈ͢Δ ίϯςφͷentrypointͰ… ϒϥϯνΛ੾Γସ͑Δ - git (clone|fetch) && switch Ͱ࢖͍͍ͨϒϥϯνʹ੾Γସ͑Δ - git switch origin/$GIT_BRANCH ← ىಈ࣌ʹࢦఆͨ͠ϒϥϯν DBͳͲͷ֎෦ϦιʔεΛ༻ҙ͢Δ - ࡞੒ʹֻ͕͔࣌ؒΒͳ͍ɺैྔ՝ۚͳϦιʔε͸ͦͷ৔Ͱ࡞੒ - $SUBDOMAIN Λ໊લʹؚΊͯผͷ΋ͷͱͯ͠࡞Δ - DynamoDB ͷςʔϒϧͱ͔SQS queueͱ͔

Slide 20

Slide 20 text

WebΞϓϦέʔγϣϯΛmirage-ecsͰىಈ͢Δ ىಈʹֻ͕͔࣌ؒΔɺ࠷௿՝ֹ͕ۚେ͖͍Ϧιʔε͸ڞ༻͢Δ޻෉ ྫ: RDS (MySQL) - σʔλϕʔεΛ$SUBDOMAINΛݩʹͯ͠࡞Δ - DBNAME=$(echo $SUBDOMAIN | tr - _) mysql -e "CREATE DATABASE IF NOT EXISTS $DBNAME ..." ྫ: Elas'Cache Redis - key_prefix Λ ${SUBDOMAIN}: ʹͯ͠࿦ཧతʹ෼཭ (ΫϥΠΞϯτϥΠϒϥϦͷػೳ)

Slide 21

Slide 21 text

WebΞϓϦέʔγϣϯΛ mirage-ecsͰىಈ ֎෦Ϧιʔεͷ४උ͕ऴΘͬͨΒىಈ - DB migra*on΍ॳظσʔλͷimport - ϥΠϒϥϦͷߋ৽ (CPAN, Gem...)ɺϏϧυ - αʔόʔىಈ (plackup, rails s...) ىಈͨ͠؀ڥ΁ͷReverse Proxy͸mirage-ecs ͕ࣗಈͰఆٛͯ͘͠Ε·͢

Slide 22

Slide 22 text

mirageҰ଒ͷྺ࢙

Slide 23

Slide 23 text

2014೥ mirage ஀ੜ "DockerͰඇΤϯδχΞͰ΋։ൃ؀ڥΛ্͛Լ͛Ͱ͖Δɺ mirageͱ͍͏πʔϧΛ࡞Γ·ͨ͠" https://techblog.kayac.com/mirage_for_docker.html 2014೥8݄ @acidlemon ͕࡞੒ɺϦϦʔε ϗετ্ͰDockerίϯςφΛىಈͯ͠Reverse Proxy͢Δ࢓૊Έ

Slide 24

Slide 24 text

mirage ֓೦ਤ

Slide 25

Slide 25 text

mirage͸ͱͯ΋ศརͩͬͨ ͪΐͬͱେ͖ΊͷΠϯελϯεΛ༻ҙ͢Ε͹ɺ ݸผͷ։ൃ؀ڥ͕͍ͭ͘Ͱ΋͙͢ʹىಈͰ͖ͯ࠷ߴʂ ͔࣌͠͠͸ྲྀΕͯ2018ʙ৽نϓϩδΣΫτͰίϯςφ(ECS)؀ڥ͕ओྲྀʹ 2019ʙ ͍Α͍Αେίϯςφ࣌୅ ৽ن͚ͩͰ͸ͳ͘طଘͷEC2ͷαʔϏε΋ECSʹҠߦ͍ͯ͘͠ྲྀΕ

Slide 26

Slide 26 text

ຊ൪͕ECSʹͳͬͯmirageʹͪΐͬͱෆຬ͕ ىಈ͢Δ؀ڥ͸ϗετͷDockerͰىಈ͢Δʮίϯςφʯ mirageͱผͷϗετͰίϯςφΛىಈ͢Δ͜ͱ͸Ͱ͖ͳ͍ (remoteͰdocker APIΛୟ͚͹࿦ཧతʹ͸Ͱ͖Δ͕ ํ๏͸༻ҙ͞Ε͍ͯͳ͔ͬͨ) ؀ڥ໊/ίϯςφͷରԠΛLevelDBͰϩʔΧϧετϨʔδʹه࿥ ͭ·Γϗετ1୆Ͱͷಈ࡞͕લఏ

Slide 27

Slide 27 text

mirageͷݶք - γϯάϧϗετߏ੒ େྔͷ؀ڥΛىಈ͢Δʹ͸େ͖ͳ1୆ͷΠϯελϯε͕ඞཁ → CPU͸͋Δఔ౓ΦʔόʔίϛοτͰ͖Δ͕ϝϞϦ͸ඞཁ ىಈ࣌΍ϚΠάϨʔγϣϯ࣌ʹϗετͷετϨʔδΛࠅ࢖͢Δ → IO͕଎͍ΠϯελϯεͰಈ͔͍ͨ͠ EC2ͳΒi3ΠϯελϯεͷΤϑΣϝϥϧSSDͱ͔ εέʔϧ͍ͨ͠ͱ͖=ಈ͍͍ͯΔϗετ͕ݶքʹୡͨ͠ͱ͖ Ұ౓؀ڥΛશ෦མͱͯ͠ىಈ͠௚͔͢͠ͳ͍

Slide 28

Slide 28 text

mirageͷ՝୊ - αΠυΧʔΛ࣋ͯͳ͍ ؀ڥͱͯ͠ىಈ͢Δ୯Ґ = ίϯςφ ඞཁͳαʔόʔɺϛυϧ΢ΣΞΛશͯ٧ΊࠐΜͰsupervisorͰىಈ foreman (Ruby) / kazeburo͞ΜͷProclet (Perl) / ma;n͞Μͷgoreman (Go) ͋ΒΏΔ΋ͷ͕શ෦ೖΓͷಛ੝Γίϯςφʹ

Slide 29

Slide 29 text

2019೥6݄ mirage-ecs஀ੜ ։ൃ؀ڥ͚ͩͷͨΊʹEC2Λҡ࣋ͨ͘͠ͳ͍ ϓϩϏδϣχϯά΋ύον౰ͯ΋࠶ىಈ΋໘ ౗ εέʔϥϒϧͳmirage͕΄͍͠! ͍ͭΧοͱͳͬͯ mirageΛforkͯ͠mirage-ecsΛ։ൃ ༨͍ͬͯͨ༗ٳΛ3೔ফԽͨ͠ΒͰ͖ͨ ͦͷޙ acidlemon/mirage-ecs ʹtransfer

Slide 30

Slide 30 text

mirage ͱ mirage-ecs

Slide 31

Slide 31 text

mirage → mirage-ecs LevelDB → ετϨʔδϨε - ReverseProxyͷͨΊʹʮ؀ڥ໊ʯ->ʮIPΞυϨεʯͷϚοϐϯά͕ඞཁ - ECSλεΫʹ͸λά͕࣋ͯΔ - ؀ڥ໊ͳͲͷϝλσʔλ͸λάʹೖΕΔɺIPΞυϨε͸ECS͕஌͍ͬͯ Δ - ఆظతʹECS APIͰλεΫͱIPΞυϨεΛऔಘͯ͠ReverseProxyఆٛΛ ߋ৽ αΠυΧʔΛ࣋ͯΔ - ʮ؀ڥ=ίϯςφʯ→ʮ؀ڥ=ECSλεΫ(ίϯςφ࠷େ10ݸ)ʯ

Slide 32

Slide 32 text

mirage → mirage-ecs γϯάϧϗετߏ੒ → ෳ਺୆ߏ੒ʹͰ͖Δ - ؀ڥ͸mirage͕ಈ࡞͢Δϗετ্Ͱ͸ͳ͘ಠཱͯ͠ىಈ - mirage-ecsࣗମ͸ετϨʔδϨεͳͷͰෳ਺୆Ͱಈ࡞Ͱ͖Δ ͱ͸͍͑Proxy͔͠͠ͳ͍ͷͰ100؀ڥ͋ͬͯ΋1୆Ͱे෼ σϓϩΠ΋rollingͰOK - ؀ڥͱ͸VPC಺Ͱ௨৴͢ΔͷͰෳ਺୆Ͱಈ࡞Ͱ͖Δ

Slide 33

Slide 33 text

mirage → mirage-ecs 1୆ͷΠϯελϯε+mirage(ϓϩηε)+ෳ਺ͷDockerίϯςφ(ϓϩηε) ͔Β ෳ਺ͷΠϯελϯε(ECSΫϥελ) + mirage-ecs(ECSαʔϏε) + ෳ਺ͷ؀ڥ(ECSλεΫ) Πϯελϯε → Ϋϥελ / ϓϩηε → λεΫ εέʔϥϏϦςΟΛ֫ಘ͢ΔͨΊͷίϯςφٕज़ʹ৐ͬͨਖ਼౷ਐԽ

Slide 34

Slide 34 text

΋͏͙͢10ࡀʹͳΔαʔϏε΋Ҡߦ͠·ͨ͠ https://techblog.kayac.com/2021/12/20/120000 https://commojun.github.io/yapc2022/

Slide 35

Slide 35 text

mirage-ecsͷઃܭͱ࣮૷

Slide 36

Slide 36 text

mirage-ecs = Go੡ͷWeb APIαʔόʔ݉reverse proxy ϝΠϯͷHTTPαʔόʔ: ϦΫΤετΛશ෦ड͚ͯHostϔομΛΈΔ - mirage.* → ΞϓϦέʔγϣϯϋϯυϥΛ࣮ߦ - ͦΕҎ֎ → HostʹରԠͨ͠؀ڥѼͯͷReverseProxyΛ࣮ߦ ͦͷଞͷgorou%ne worker - ECS APIΛୟ͍ͯReverseProxyΛߋ৽͢Δworker ʮ؀ڥ=λεΫʯ͕૿͑ͨΒReveseProxyΛ࡞੒ͯ͠mapʹ௥Ճ ݮͬͨΒReveseProxyΛmap͔Β࡟আ - ϦΫΤετ਺ूܭΛCloudWatchʹ౤͛Δworker

Slide 37

Slide 37 text

؀ڥ͝ͱͷreverse proxyͷ࣮૷ github.com/methane/rproxy WebSocketରԠͷ୯ҰϗετѼͷReverseProxy࣮૷ϥΠϒϥϦ 11೥લʹ࡞ΒΕͨ΋ͷ(ͦͷޙߋ৽͸ͳ͍͕…) Goͷඪ४ϞδϡʔϧͷΈͰͰ͖͍ͯΔͷͰ Go 1.22(2024೥)Ͱ΋ͪΌΜͱಈ͘ʂʂ ALB΋WebSocketʹରԠ͍ͯ͠ΔͷͰ Կ΋ߟ͑ͣʹWebSocket͕ಈ͖·͢

Slide 38

Slide 38 text

ετϨʔδϨε ؅ཧ͢Δ΋ͷΛݮΒͯ͠σϓϩΠΛ༰қʹ͢ΔͨΊ mirage-ecs͸ECSαʔϏεΛσϓϩΠ͢Ε͹ಈ࡞͢Δ - ॳ୅mirage͸ετϨʔδʹLevelDB(KVS)Λ࢖͍ͬͯͨ - AWSઐ༻ͳͷͰDynamoDBΛ࢖͏͜ͱ΋ߟ͕͑ͨ…… - ECSͷλάʹ৘ใΛ࣋ͭ͜ͱͰετϨʔδϨεʹ ؀ڥ͸͍͍ͤͥ100+ݸఔ౓ͳͷͰ͜ΕͰे෼ ਓ͸ӬଓετϨʔδΛ؅ཧͨ͘͠ͳ͍

Slide 39

Slide 39 text

ίϯϑΟάϨε ॳ୅mirageͰඞཁͩͬͨઃఆ͸͜Ε͚ͩ host: webapi: mirage.example.com reverse_proxy_suffix: ".example.com" listen: http: - listen: 80 target: 80 ͜Ε͙Β͍ͳΒखͰॻ͍ͯ΋໰୊ͳ͍͕…

Slide 40

Slide 40 text

ECSͰ͸λεΫΛىಈ͢ΔͨΊͷઃఆ͕(Ͳ͏ͯ͠΋)ඞཁ ecs: region: "ap-northeast-1" cluster: mycluster default_task_definition: myapp enable_execute_command: true launch_type: FARGATE network_configuration: awsvpc_configuration: subnets: - subnet-aaaa0000 - subnet-bbbb1111 - subnet-cccc2222 security_groups: - sg-11112222 - sg-aaaagggg assign_public_ip: ENABLED

Slide 41

Slide 41 text

ࣗಈઃఆػೳΛ࡞ͬͨ mirage-ecsࣗମ͕ECSͰಈ͘લఏͳͷͰࣗ෼ࣗ਎ͷઃఆΛྲྀ༻͢Δ - λεΫϝλσʔλAPIͰࣗ෼͕ಈ͍͍ͯΔΫϥελ໊ͱλεΫIDΛऔಘ - λεΫID͔ΒECSαʔϏε໊Λऔಘ (ͳ͔ͥ͜Ε͸ϝλσʔλʹ͸ͳ͍) - ECSαʔϏεͷNetworkConfigura

Slide 42

Slide 42 text

mirage-ecsͷ࣮ફతͳӡ༻

Slide 43

Slide 43 text

mirage link ECSλεΫʹ͸10ίϯςφ·ͰؚΊΒΕΔ͕଍Γͳ͘ͳͬͯࠔͬͨͷͰ… 1. ىಈ࣌ʹෳ਺ͷλεΫఆٛ(A,B)Λ౉͢(Ϣʔβʔ) 2. ͦΕͧΕͷλεΫఆ͔ٛΒλεΫa,bΛىಈ͢Δ (mirage-ecs) 3. ίϯςφ໊ͱλεΫͷIPΞυϨεͰRoute53ʹ໊લΛఆٛ(mirage-ecs) nginx.foo.example.com λεΫaͷIPΞυϨε webapp.foo.example.com λεΫaͷIPΞυϨε backend.foo.example.com λεΫbͷIPΞυϨε sidecar.foo.example.com λεΫbͷIPΞυϨε ෳ਺ͷλεΫΛ1ͭͷʮ؀ڥʯͱͯ͠ѻ͑Δ

Slide 44

Slide 44 text

ΞΫηε਺ܭଌͱఆظ࡟আ ൺֱత௿ίετͱ͸͍͑ɺ؀ڥ਺ʹൺྫͯ͠ίετ͸ֻ͔Δ ࢖͍ͬͯͳ͍؀ڥΛࣗಈతʹఀࢭ͍ͨ͠ʂ - http.TransportΛΧελϚΠζͯ͠ReverseProxyʹ ΞΫηεΧ΢ϯλʔΛ࣮૷ - ʮ؀ڥʯ୯ҐͰ1෼͋ͨΓͷHTTPΞΫηε਺Λه࿥ - ຖ෼CloudWatchʹMetricsͱͯ͠ૹ৴ ͜ΕͰʮҰఆظؒΞΫηε͕ͳ͍(=࢖ΘΕ͍ͯͳ͍)؀ڥʯ͕෼͔Δ

Slide 45

Slide 45 text

POST /api/purge { "excludes": ["foo", "bar"], "exclude_tags": ["branch:preview"], "duration": 86400 } excludes: ಛఆͷ؀ڥ໊͸আ֎ exclude_tags: ࢦఆͨ͠λά͕෇͍͍ͯΔ؀ڥ͸আ֎ duration: աڈࢦఆͨ͠ඵ਺ʹΞΫηε͕ͳ͍؀ڥΛ࡟আ͢Δ ࢭΊͨ͘ͳ͍؀ڥ΋͋ΔͷͰআ֎৚݅ΛࢦఆՄೳ(ސ٬޲͚ͱ͔)

Slide 46

Slide 46 text

؀ڥ͕ىಈͰ͖ͳ͍ཧ༝Λ஌Γ͍ͨ ECSλεΫɺཱͨͳ͍ͱ͖ࠔΓ·͢ΑͶ… github.com/fujiwara/tracer "Amazon ECS λεΫͷΠϕϯτͱϩάΛ࣌ܥྻͰग़͢ tracer Λ࡞ͬͨ"4 - λεΫʹؔ࿈͢ΔΠϕϯτ(࡞੒ɺىಈ։࢝ɺpull։࢝ͱఀࢭɺఀࢭ։ ࢝ɺఀࢭ׬ྃͳͲ) - λεΫ಺ͷίϯςφ͕ CloudWatch Logs ʹग़ྗͨ͠ϩά - (ECS αʔϏε͔Βىಈ͞ΕͨλεΫͷ৔߹) αʔϏεͷΠϕϯτϩά ͜ΕΛmirage-ecsͷWebUI͔Β͙͢ݟΒΕΔΑ͏ʹ 4 h$ps:/ /techblog.kayac.com/ecs-task-tracer

Slide 47

Slide 47 text

tracerͷग़ྗྫ (ىಈ→ఀࢭ) 2024-01-31T07:05:17.529Z TASK Created 2024-01-31T07:05:32.718Z CONTAINER:nginx LastStatus:PENDING HealthStatus:UNKNOWN 2024-01-31T07:05:32.718Z TASK LastStatus:PENDING 2024-01-31T07:05:22.775Z TASK Connected 2024-01-31T07:05:32.391Z TASK Pull started 2024-01-31T07:05:39.561Z TASK Pull stopped 2024-01-31T07:05:39.590Z TASK Started 2024-01-31T07:05:40.070Z CONTAINER:nginx LastStatus:PENDING HealthStatus:UNKNOWN 2024-01-31T07:05:40.070Z TASK LastStatus:PENDING 2024-01-31T07:05:40.070Z CONTAINER:nginx LastStatus:RUNNING HealthStatus:UNKNOWN 2024-01-31T07:05:40.070Z TASK LastStatus:RUNNING 2024-01-31T07:05:39.573Z CONTAINER:nginx /docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration 2024-01-31T07:05:39.573Z CONTAINER:nginx /docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/ 2024-01-31T07:05:39.576Z CONTAINER:nginx /docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh -- (ུ) -- 2024-02-04T01:03:04.797Z TASK LastStatus:STOPPED 2024-02-04T01:02:50.022Z TASK Stopping 2024-02-04T01:02:50.022Z TASK StoppedReason:Terminate requested by Mirage 2024-02-04T01:02:50.022Z TASK StoppedCode:UserInitiated 2024-02-04T01:02:52.015Z CONTAINER:nginx 2024/02/04 01:02:52 [notice] 1#1: signal 15 (SIGTERM) received, exiting 2024-02-04T01:02:52.018Z CONTAINER:nginx 2024/02/04 01:02:52 [notice] 34#34: exiting 2024-02-04T01:02:52.018Z CONTAINER:nginx 2024/02/04 01:02:52 [notice] 35#35: exiting 2024-02-04T01:02:52.018Z CONTAINER:nginx 2024/02/04 01:02:52 [notice] 34#34: exit

Slide 48

Slide 48 text

tracerͷग़ྗྫ (ىಈࣦഊ) 2024-02-04T01:09:02.676Z TASK Created 2024-02-04T01:09:08.180Z TASK LastStatus:STOPPED 2024-02-04T01:09:08.180Z TASK LastStatus:DEPROVISIONING 2024-02-04T01:09:08.180Z TASK LastStatus:PROVISIONING 2024-02-04T01:09:06.503Z TASK Connected 2024-02-04T01:09:21.109Z TASK Execution stopped 2024-02-04T01:09:31.147Z TASK Stopping 2024-02-04T01:09:31.147Z TASK StoppedReason:CannotPullContainerError: pull image manifest has been retried 1 time(s): failed to resolve ref docker.io/library/nginx:lates: docker.io/library/nginx:lates: not found 2024-02-04T01:09:31.147Z TASK StoppedCode:TaskFailedToStart imageΛpullͰ͖͍ͯͳ͍ͨΊ StoppedCode:TaskFailedToStart ͳͷ͕͙͢෼͔Δ

Slide 49

Slide 49 text

ଞʹ΋ศརػೳ͕͍Ζ͍Ζ ೝূೝՄͱ͔ɺ؀ڥ໊ͷϫΠϧυΧʔυରԠͱ͔… ৄ͘͠͸ github.com/acidlemon/mirage-ecs ΛͲ͏ͧ

Slide 50

Slide 50 text

·ͱΊ ʮϒϥϯνผ։ൃɾݕূ؀ڥʯ͕͋Δͱ։ൃޮ཰্͕͕Γ·͢ ͕ɺ࣮૷ํ๏ʹΑͬͯ͸ίετ͕େ͖͘ͳΓ͕ͪͰ͢ acidlemon/mirage-ecs ͸ಠཱͨ͠ʮ؀ڥʯΛECSλεΫͱͯ͠ىಈ͢Δ গͳ͍ίετͰɺ͍ͭ͘Ͱ΋ߴ଎ʹݕূ؀ڥΛىಈͰ͖Δ OSS Ͱ͢