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
ECS/Fargateの活用事例 (Ruby on Rails編)
Search
adachin0817
September 18, 2020
Technology
3
2.9k
ECS/Fargateの活用事例 (Ruby on Rails編)
【アソビュー×ランサーズ】AWSでのオーケストレーションツールの活用事例(EKS vs ECS)
https://lancersrecruit.connpass.com/event/187989/
adachin0817
September 18, 2020
Tweet
Share
More Decks by adachin0817
See All by adachin0817
ゼロから創る横断SREチーム 挑戦と進化の軌跡
rvirus0817
2
270
入社1ヶ月でここまでやった!Findy Toolsインフラ支援の最適化
rvirus0817
11
7.5k
メンティー同士で輪読会を始めたら学びしかなかった
rvirus0817
1
1k
MENTAを5年やってみて:メンタリングで意識していること
rvirus0817
0
470
Lancersをコンテナへ本番移行する取り組み
rvirus0817
1
1.8k
~CircleCIでTerraformリリースのサーバーレス化~ インフラの独自リリースを継続的リリースへ
rvirus0817
0
3.7k
Terraform v0.12.29 → v1.0.5にバージョンアップする上で気をつけること
rvirus0817
0
4.1k
MENTAをAWSに移行して振り返る(ECS/Fargate + Laravel編)
rvirus0817
3
8.7k
ECS/Fargateの活用事例(CakePHP編)
rvirus0817
1
4.1k
Other Decks in Technology
See All in Technology
React Routerで実現する型安全なSPAルーティング
sansantech
PRO
2
190
Working as a Server-side Engineer at LY Corporation
lycorp_recruit_jp
0
320
どちらを使う?GitHub or Azure DevOps Ver. 24H2
kkamegawa
0
1k
Amazon Kendra GenAI Index 登場でどう変わる? 評価から学ぶ最適なRAG構成
naoki_0531
0
130
Storage Browser for Amazon S3
miu_crescent
1
280
あの日俺達が夢見たサーバレスアーキテクチャ/the-serverless-architecture-we-dreamed-of
tomoki10
0
500
マイクロサービスにおける容易なトランザクション管理に向けて
scalar
0
170
UI State設計とテスト方針
rmakiyama
2
740
コンテナセキュリティのためのLandlock入門
nullpo_head
2
320
10分で学ぶKubernetesコンテナセキュリティ/10min-k8s-container-sec
mochizuki875
3
370
Wantedly での Datadog 活用事例
bgpat
1
580
APIとはなにか
mikanichinose
0
110
Featured
See All Featured
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
45
2.2k
Speed Design
sergeychernyshev
25
670
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
2
290
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
28
4.4k
We Have a Design System, Now What?
morganepeng
51
7.3k
Testing 201, or: Great Expectations
jmmastey
40
7.1k
StorybookのUI Testing Handbookを読んだ
zakiyama
27
5.3k
The Pragmatic Product Professional
lauravandoore
32
6.3k
YesSQL, Process and Tooling at Scale
rocio
169
14k
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
1
100
XXLCSS - How to scale CSS and keep your sanity
sugarenia
248
1.3M
Building a Scalable Design System with Sketch
lauravandoore
460
33k
Transcript
2020/9/18 ʲΞιϏϡʔ×ϥϯαʔζʳAWSͰͷΦʔέετϨʔγϣϯπʔϧͷ׆༻ࣄྫ(EKS vs ECS) ECS/Fargateͷ׆༻ࣄྫ (Ruby on Railsฤ) ϥϯαʔζגࣜձࣾ SRE/҆ୡ
ྋ
2020/9/18 ʲΞιϏϡʔ×ϥϯαʔζʳAWSͰͷΦʔέετϨʔγϣϯπʔϧͷ׆༻ࣄྫ(EKS vs ECS) ΞδΣϯμ ɾࣗݾհ ɾݱࡏऔΓΜͰ͍Δ͜ͱ ɾECS/FargateͷϝϦοτσϝϦοτ ɾ։ൃڥΛ࡞ΔϙΠϯτ
ɾStg/ຊ൪ڥͷߏʹ͍ͭͯ ɾSSH/࡞ۀ༻ίϯςφʮdevopsʯʹ͍ͭͯ ɾCircleCIʹΑΔίϯςφσϓϩΠ ɾECS Scheduled TasksʹΑΔόον࣮ʹ͍ͭͯ ɾϩά/ίϯςφࢹʹ͍ͭͯ ɾ·ͱΊ
2020/9/18 ʲΞιϏϡʔ×ϥϯαʔζʳAWSͰͷΦʔέετϨʔγϣϯπʔϧͷ׆༻ࣄྫ(EKS vs ECS) ࣗݾհ
2020/9/18 ʲΞιϏϡʔ×ϥϯαʔζʳAWSͰͷΦʔέετϨʔγϣϯπʔϧͷ׆༻ࣄྫ(EKS vs ECS) ࣗݾհ ɾ҆ୡ ྋ(adachin) ɾLancers SRE
2018~ ɾ@adachin0817 ɾRVIRUS0817 ɾblog.adachin.me ɾwiki.adachin.me ɾOSS : ɾCakePHPͰݸਓαʔϏε։ൃத
2020/9/18 ʲΞιϏϡʔ×ϥϯαʔζʳAWSͰͷΦʔέετϨʔγϣϯπʔϧͷ׆༻ࣄྫ(EKS vs ECS) ݱࡏऔΓΜͰ͍Δ͜ͱ
2020/9/18 ʲΞιϏϡʔ×ϥϯαʔζʳAWSͰͷΦʔέετϨʔγϣϯπʔϧͷ׆༻ࣄྫ(EKS vs ECS) ݱࡏऔΓΜͰ͍Δ͜ͱ ɾڈळ ɾάϧʔϓձࣾ(γΫϩϚʔέςΟϯά) ɾ͘͞ΒͷΫϥυͰӡ༻ ɾॳΊͯECS/FargateʹҠߦνϟϨϯδ
ɾࠓ4݄ʹҠߦྃ ɹɾࠓճͪ͜ΒͷΛ͠·͢!! ɾݱࡏ(5݄͔Β) ɾάϧʔϓձࣾ(Lancers Agency)ɹ ɾECS/FargateͰҠߦத!!
2020/9/18 ʲΞιϏϡʔ×ϥϯαʔζʳAWSͰͷΦʔέετϨʔγϣϯπʔϧͷ׆༻ࣄྫ(EKS vs ECS) EC2ͱൺֱͨ͠ECS/Fargate ͷϝϦοτσϝϦοτ
2020/9/18 ʲΞιϏϡʔ×ϥϯαʔζʳAWSͰͷΦʔέετϨʔγϣϯπʔϧͷ׆༻ࣄྫ(EKS vs ECS) EC2ͱൺֱͨ͠ECS/FargateͷϝϦοτσϝϦοτ ϝϦοτ ɾଐਓԽ͕ൃੜ͠ͳ͍ ɾImmutableͳαʔόʔͷӡ༻ ɹɾ҆ఆӡ༻ɺӡ༻ޮͷΞοϓ
ɾϗετΠϯελϯεͷཧ͕ল͚Δ ɾλεΫ୯ҐͰࣗ༝ʹϦιʔεมߋՄೳ ɾεέʔϧΞτͷ͢͠͞ σϝϦοτ ɾσόοά͕ͮ͠Β͍ ɾdocker execSSH͕Ͱ͖ͳ͍ ɾλεΫͷىಈ͕Ί ɹɾόον࣮ߦ͘ͳΔ ɾྉ͕͓ۚߴΊ ɹɾEC2ΑΓׂߴʢ1ׂʙ2ׂʣ
2020/9/18 ʲΞιϏϡʔ×ϥϯαʔζʳAWSͰͷΦʔέετϨʔγϣϯπʔϧͷ׆༻ࣄྫ(EKS vs ECS) ։ൃڥΛ࡞Δ ϙΠϯτ
2020/9/18 ʲΞιϏϡʔ×ϥϯαʔζʳAWSͰͷΦʔέετϨʔγϣϯπʔϧͷ׆༻ࣄྫ(EKS vs ECS) ։ൃڥΛ࡞ΔϙΠϯτ ɾຊ൪ڥͱಉͷߏΛ࠶ݱ ɾELB(H2O)ίϯςφ(ϦόʔεϓϩΩγ) ɾApp(ίϯςφ) ɹɾruby:2.5.7
ɹɾRails4.2.11 ɹɾNginx ɾMySQLίϯςφ ɹɾ5.7 ɾ֤ΞϓϦέʔγϣϯͷىಈSupervisorͰཧ ɾbundle installAppίϯςφͰϩάΠϯ࣌ʹ࣮ߦ ɹɾsupervisorctlͰΞϓϦΛrestart͢ΔΑ͏ʹ
2020/9/18 ʲΞιϏϡʔ×ϥϯαʔζʳAWSͰͷΦʔέετϨʔγϣϯπʔϧͷ׆༻ࣄྫ(EKS vs ECS) Stg/ຊ൪ڥͷ ߏʹ͍ͭͯ
2020/9/18 ʲΞιϏϡʔ×ϥϯαʔζʳAWSͰͷΦʔέετϨʔγϣϯπʔϧͷ׆༻ࣄྫ(EKS vs ECS) Stg/ຊ൪ڥͷߏʹ͍ͭͯ ɾTerraformͰશϦιʔείʔυԽ ɾStgڥλεΫ1ͭ ɾdevopsίϯςφͷར༻ ɾDBRDS
AuroraʹҠߦ ɾը૾S3ʹอଘ ɾϩάCloudWatch Logs ɾόονECS Scheduled Tasks ɾ෦ࠪ(ϩάͷू) ɹɾAmazon Kinesis ɾσϓϩΠCircleCIͷΈͰ࣮ ɾࢹDatadog
2020/9/18 ʲΞιϏϡʔ×ϥϯαʔζʳAWSͰͷΦʔέετϨʔγϣϯπʔϧͷ׆༻ࣄྫ(EKS vs ECS) SSH/࡞ۀ༻ίϯςφ ʮdevopsʯʹ͍ͭͯ
2020/9/18 ʲΞιϏϡʔ×ϥϯαʔζʳAWSͰͷΦʔέετϨʔγϣϯπʔϧͷ׆༻ࣄྫ(EKS vs ECS) SSH/࡞ۀ༻ίϯςφʮdevopsʯʹ͍ͭͯ ɾAppʹSSH͠ͳ͍ ɾSSH/࡞ۀ༻ίϯςφ(Appͱಉ) ɹɾdevopsͱ໋໊ ɾίϚϯυͰRDSଓ
ɹɾdumprestore ɾaws cliͷར༻ ɾrails consoleͰͷσόοά ɾSSMͷSession Manager ͋Δ͕ ɹɾखܰʹ౿Έ͔ΒSSHΛ͍ͨͨ͠Ί ɾVPC PeeringͰϥϯαʔζͷωοτϫʔΫ͔ΒSSHϩάΠϯ
2020/9/18 ʲΞιϏϡʔ×ϥϯαʔζʳAWSͰͷΦʔέετϨʔγϣϯπʔϧͷ׆༻ࣄྫ(EKS vs ECS) CircleCIʹΑΔ ίϯςφσϓϩΠʹ͍ͭͯ
2020/9/18 ʲΞιϏϡʔ×ϥϯαʔζʳAWSͰͷΦʔέετϨʔγϣϯπʔϧͷ׆༻ࣄྫ(EKS vs ECS) CircleCIʹΑΔStg/ຊ൪σϓϩΠʹ͍ͭͯ(ॳظ) ɾCircleCIͷOrbs ɹɾDockerfileͷbuild ɹɾECRpush ɹɾECSϦϏδϣϯͷߋ৽
ɹɾαʔϏελεΫఆٛͷߋ৽ ɹɾDBϚΠάϨʔγϣϯ ɹɾrspec ɾgit flow ɾdevelopϒϥϯν ɹɾϚʔδ͢ΔͱStgʹϦϦʔε ɾmasterϒϥϯν ɹɾϚʔδ͢Δͱຊ൪ʹϦϦʔε
2020/9/18 ʲΞιϏϡʔ×ϥϯαʔζʳAWSͰͷΦʔέετϨʔγϣϯπʔϧͷ׆༻ࣄྫ(EKS vs ECS) APIܦ༝ͰͷStgڥͷσϓϩΠ(ݱࡏ) ɾStgڥͷσϓϩΠ ɹɾgithub flow ɹɾγΣϧεΫϦϓτ
ɹɹɾҙͷϒϥϯνΛࢦఆ ɾૉૣ͘σϓϩΠ͕Մೳ ɹɾ։ൃޮ͕Ξοϓ ɾTerraform CIڥΛ࣮ $ sh deploy.sh ԼهͷΑ͏ʹϒϥϯνΛࢦఆ࣮ͯ͠ߦ͍ͯͩ͘͠͞ɻ (ྫ) sh deploy.sh ϒϥϯν໊ $ sh deploy.sh fix-nginx { "number" : 74, "state" : "pending", "id" : "xxxxxx-xxxxx-xxxxx-xxx-xxxxxxxx", "created_at" : "2020-08-27T06:14:43.973Z" } ϒϥϯν໊/ fix-nginx ͷStgσϓϩΠΛ։࢝͠·ͨ͠!
2020/9/18 ʲΞιϏϡʔ×ϥϯαʔζʳAWSͰͷΦʔέετϨʔγϣϯπʔϧͷ׆༻ࣄྫ(EKS vs ECS) όονͷ࣮ʹ͍ͭͯ
2020/9/18 ʲΞιϏϡʔ×ϥϯαʔζʳAWSͰͷΦʔέετϨʔγϣϯπʔϧͷ׆༻ࣄྫ(EKS vs ECS) ECS Scheduled TasksʹΑΔόον࣮ʹ͍ͭͯ ɾࠓ·Ͱ ɹɾgem
whenever ɹɾschedule.rb ɾݱࡏ ɹɾECS Scheduled Tasks ɹɹɾCloudWatchͷΠϕϯτϧʔϧ ɹɹɾTerraformԽ { "containerOverrides": [ { "name": "HogeWorker", "command": ["bundle","exec","rails","runner","HogeWorker.new.execute"] } ] }
2020/9/18 ʲΞιϏϡʔ×ϥϯαʔζʳAWSͰͷΦʔέετϨʔγϣϯπʔϧͷ׆༻ࣄྫ(EKS vs ECS) ϩάʗίϯςφࢹ ʹ͍ͭͯ
2020/9/18 ʲΞιϏϡʔ×ϥϯαʔζʳAWSͰͷΦʔέετϨʔγϣϯπʔϧͷ׆༻ࣄྫ(EKS vs ECS) ϩά/ίϯςφࢹʹ͍ͭͯ ɾΞΫηε/ΞϓϦϩάɺRDSࠪ/Τϥʔϩά ɹɾCloudWatch Logsʹ ɹɾࠓ·Ͱ
ɹɹɾLambdaͰS3ʹγϯΫɹɹ ɹɹɾPythonͰ࣮͍ͯͨͨ͠Ίӡ༻ίετΞοϓ ɹɾࠓճ ɹɹɾAmazon Kinesis Data FirehoseͰS3ʹू ɹɹɾTerraformԽ ɾࢹ ɹɾMackerel→DatadogʹҠߦ ɹɾλεΫఆٛʹdatadog-agentΛಈ࡞ͤ͞ΔΑ͏ʹ ɹɾcpu:10ɺmemory:256 TerraformԽ
2020/9/18 ʲΞιϏϡʔ×ϥϯαʔζʳAWSͰͷΦʔέετϨʔγϣϯπʔϧͷ׆༻ࣄྫ(EKS vs ECS) ·ͱΊ
2020/9/18 ʲΞιϏϡʔ×ϥϯαʔζʳAWSͰͷΦʔέετϨʔγϣϯπʔϧͷ׆༻ࣄྫ(EKS vs ECS) ·ͱΊ ɾγϯϓϧͳߏͰ࣮ݱͰ͖ͨ ɾখ͍͞αʔϏε͔ΒECS/FargateԽத ɾDockerΠϝʔδͱλεΫఆٛͰӡ༻Մೳ ɾॳΊͯίϯςφຊ൪ӡ༻͢Δʹ͔ͳΓϋϚΔ
ɹɾϔϧενΣοΫ͕௨Βͳ͍ͱίϯςφ͕མͪͨΓ ɹɾσϓϩΠͷ࣮͕େม ɹɾLinuxྗ͕ࢼ͞ΕΔ ɾࠓޙ ɹɾRuby2.7.1/Rails6ͷόʔδϣϯΞοϓ ɹɾίϯςφͷ੬ऑੑݕ (Trivy) ɹɾσϓϩΠ͕10͔͔ΔͷͰվળ ɹɾChatOpsͰͷϦϦʔε ɹɾDatadogͰϩά࿈ܞ ɹɾϥϯαʔζຊՈίϯςφҠߦʹνϟϨϯδ
2020/9/18 ʲΞιϏϡʔ×ϥϯαʔζʳAWSͰͷΦʔέετϨʔγϣϯπʔϧͷ׆༻ࣄྫ(EKS vs ECS) SREٻΉʂʂ ECS/Fargate/PHPͰͷڥΛ͓͠·͢ʂ
2020/9/18 ʲΞιϏϡʔ×ϥϯαʔζʳAWSͰͷΦʔέετϨʔγϣϯπʔϧͷ׆༻ࣄྫ(EKS vs ECS)