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
eb_with_multi_container_docker
Search
Takumi KANZAKI
June 27, 2016
Technology
1
2.3k
eb_with_multi_container_docker
# JAWS-UGおコンテナ支部 #5
- EB with multi-container Docker をproductionで1年間運用して起きたこと
Takumi KANZAKI
June 27, 2016
Tweet
Share
More Decks by Takumi KANZAKI
See All by Takumi KANZAKI
SmartHRにおけるアカウントモデルの移行のはなし/Story of migration of account model in SmartHR - Rails Developers Meetup 2018 Day 4 Nouvelle Vague -
tknzk
6
2k
新生児〜生後6ヶ月を支えた技術/kosodate-engineer-meetup-3
tknzk
4
2.1k
kosodate_engineer_meetup_2
tknzk
3
5.6k
AdServer Casual Monitoring by fluentd, Mackerel
tknzk
0
1.7k
Other Decks in Technology
See All in Technology
【令和最新版】AWS Direct Connectと愉快なGWたちのおさらい
minorun365
PRO
5
750
TypeScript、上達の瞬間
sadnessojisan
46
13k
いざ、BSC討伐の旅
nikinusu
2
780
VideoMamba: State Space Model for Efficient Video Understanding
chou500
0
190
OCI Vault 概要
oracle4engineer
PRO
0
9.7k
第1回 国土交通省 データコンペ参加者向け勉強会③- Snowflake x estie編 -
estie
0
130
誰も全体を知らない ~ ロールの垣根を超えて引き上げる開発生産性 / Boosting Development Productivity Across Roles
kakehashi
1
230
初心者向けAWS Securityの勉強会mini Security-JAWSを9ヶ月ぐらい実施してきての近況
cmusudakeisuke
0
130
Evangelismo técnico: ¿qué, cómo y por qué?
trishagee
0
360
Lambdaと地方とコミュニティ
miu_crescent
2
370
ノーコードデータ分析ツールで体験する時系列データ分析超入門
negi111111
0
410
B2B SaaSから見た最近のC#/.NETの進化
sansantech
PRO
0
850
Featured
See All Featured
Building Adaptive Systems
keathley
38
2.3k
Designing on Purpose - Digital PM Summit 2013
jponch
115
7k
No one is an island. Learnings from fostering a developers community.
thoeni
19
3k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
47
2.1k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
232
17k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
169
50k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
33
1.9k
Making the Leap to Tech Lead
cromwellryan
133
8.9k
How STYLIGHT went responsive
nonsquared
95
5.2k
Faster Mobile Websites
deanohume
305
30k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
226
22k
Measuring & Analyzing Core Web Vitals
bluesmoon
4
130
Transcript
JAWS-UG͓ίϯςφࢧ ෦ #5 EB with multi-container Docker Λ productionͰ1ؒӡ༻ͯ͠ى͖ͨ͜ ͱ
1 VASILY Inc. 2016
Me • Takumi Kanzaki (@tknzk) • VASILY Inc. Backend Engineer
• 2015.04~ • iQONAD/ࣾ༻ٻॻπʔϧ Λ୲ ($∀$) • ࠷ۙiQON API ୲ 2 VASILY Inc. 2016
3 VASILY Inc. 2016
iQONAD • iQON͓Αͼ֎෦ΞϓϦʹࠂ৴Λߦ͍ͬͯΔADωοτϫʔΫ • 2014.10~ • ॳظ࣮~ϩʔϯν • 2weeks 4
VASILY Inc. 2016
iQONAD • software, middleware • Ruby, Rails, sinatra • MySQL,
memcached, Redis • infra • EC2, RDS • docker, ElasticBeanstalk (2015.06~) • auto-scaling 5 VASILY Inc. 2016
EB w/ multi-container docker • 2015/06~ • 1ؒproductionڥͰӡ༻ͯ͠ى͖ͨ͜ͱΛ͝հ͠·͢ 6 VASILY
Inc. 2016
Container ߏ • 4ͭͷcontainerͰՔಇ 1. ຊମͷΞϓϦέʔγϣϯ͕͍ͬͨContainer (ad-server) • ruby,supervisord 2.
httpͷϦΫΤετΛड͚͚ΔͨΊͷnginx 3. logίϨΫλͱͯ͠ͷtd-agent 4. ࢹ༻ͷmackerel-agent 7 VASILY Inc. 2016
։ൃ/ӡ༻ฤ 8 VASILY Inc. 2016
#1 middlewareͷߋ৽ • ruby 2.0 -> 2.2.3 • ϩʔϯν·Ͱ2िؒͰ։ൃΛߦͬͨ͜ͱ͔Βطଘͷ։ൃӡ༻࣮ ͷ͋Δruby
2.0.0 Ͱ։ൃ/ӡ༻͞Ε͍ͯ·ͨ͠ • 2015/11ʹdockerͷڧΈΛ׆͔ͯ͠ɺruby2.2ܥʹҠߦ • ruby2.2 • GGͷվળͷԸܙ 9 VASILY Inc. 2016
#1 middlewareͷߋ৽ • ruby 2.0 -> 2.2.3 10 VASILY Inc.
2016
#1 middlewareͷߋ৽ • ruby 2.0 -> 2.2.3 -> 2.3.1 •
ࠓͷ͡Ίʹ ruby 2.3.1Ҡߦ • ଞͷmiddlewareΧδϡΞϧʹ࠷৽ • nginx: 1.11.1 • mackerel-agent: 0.31.2 • td-agent: v2.3.1 (fluentd:v0.12.20) 11 VASILY Inc. 2016
#1 middlewareͷߋ৽ • ruby 2.4.0ਵ࣌ςετΛ͓͜ͳ͍ͬͯ·͢ • ruby 2.4.0-preview1 12 VASILY
Inc. 2016
#1 middlewareͷߋ৽ • docker ͷར • ΧδϡΞϧʹimageΛೖΕସ͑ΒΕΔ 13 VASILY Inc.
2016
#2 docker imageංେԽ • ͱ͋ΔλΠϛϯάͷdocker image size • ad_server: 924.6MB
• nginx: 134.1MB • td-agent: 448.4MB • mackerel-agent: 423.1MB 14 VASILY Inc. 2016
#2 docker imageංେԽ ͑ͬʂࢲͷdocker imageଠΓա͗..! 15 VASILY Inc. 2016
#2-2 docker imageݮ • ํ 1. Ͱ͖Δ͚ͩܰྔͳOSΛϕʔεʹ͢Δ 2. ෆඞཁͳύοέʔδΛΠϯετʔϧ͠ͳ͍ 3.
build͢Δͱ͖ʹ͚ͩඞཁͳύοέʔδΛదٓআ͢Δ 16 VASILY Inc. 2016
#2-2 docker imageݮ nginx • ެࣜͰalpine linuxΛϕʔεʹͨ͠ͷ ͕͋Δ • ࠾༻!
17 VASILY Inc. 2016
#2-2 docker imageݮ ad-server • ͱͱ CentOS6Λϕʔεʹbuild • 2ஈߏ •
ruby, supervisord, mysql ΛΈࠐΜͩimage • ↑ʹad-serverͱͯ͠ඞཁͳGemΛΈࠐΉ 18 VASILY Inc. 2016
#2-2 docker imageݮ ad-server • alpine linuxΛϕʔεʹͯ͠build • ॳظ •
build͢Δ͚ͩͯ͠আΛ͍ͯ͠ͳ͍ঢ়ଶ 19 VASILY Inc. 2016
#2-2 docker imageݮ ad-server 20 VASILY Inc. 2016
#2-2 docker imageݮ ad-server • ਫ਼ࠪ1 • mysql (mariadb-dev) ͕ͱͯେ͖͍...
• ෆཁͳόΠφϦΛআ rm /usr/lib/libmysqld* && \ rm /usr/bin/mysql* 21 VASILY Inc. 2016
#2-2 docker imageݮ ad-server • ਫ਼ࠪ2 • buildʹඞཁͳύοέʔδΛཧ • native-extensionͳGemΠϯετʔϧʹඞཁͳΛtemporaryͰ
install/uninstall • build-base (gccͳͲ) 22 VASILY Inc. 2016
#2 docker imageංେԽ • ࠷৽ͷ docker image size • ad_server:
924.6MB -> 342.7MB • nginx: 134.1MB -> 59.63MB • td-agent: 448.4MB -> 430.8MB • mackerel-agent: 423.1MB -> 357.5MB 23 VASILY Inc. 2016
#2 docker imageංେԽ • ࠷େ࣌ͷ6ׂ͙Β͍·Ͱݮ • blogॻ͖·ͨ͠ http://tech.vasily.jp/ docker_image_slim_in_alpinelinux 24
VASILY Inc. 2016
#3 base platform • EB w/multi-container docker • Amazon Linux
ͱ dockerͷΈ߹ΘͤͰෳ 25 VASILY Inc. 2016
#3 base platform • EB w/multi-container docker • Amazon Linux
2015.03 v1.4.0 docker 1.6.0 • Amazon Linux 2015.03 v1.4.1 docker 1.6.0 • Amazon Linux 2015.03 v1.4.6 docker 1.6.2 • Amazon Linux 2015.09 v2.0.8 docker 1.9.1 • Amazon Linux 2016.03 v2.1.0 docker 1.9.1 • Amazon Linux 2016.03 v2.1.1 docker 1.9.1 26 VASILY Inc. 2016
#3 base platform • ͍·গ͠ݹΊversionΛར༻ • Amazon Linux 2015.09 v2.0.8
docker 1.9.1 • Amazon Linux 2016.03mackerel-agent͕ىಈͰ͖ͳ͍ • docker͔ͩΒؔͳ͍ͱࢥ͍ͬͯͨΒىಈͰ͖ͳ͔ͬͨ.. 27 VASILY Inc. 2016
#3 base platform • hostͷdocker ͕গ͠ݹ͍ͷͰɺclientଆ͕৽͗͢͠ΔͱىಈͰ͖ ͳ͍.. • docker 1.9.1
• EBʹґଘ͠ͳ͍ܗߟ͍͖͍͑ͯͨ 28 VASILY Inc. 2016
#3 base platform • ࠓݟͨΒ, Amazon Linux 2016.03 docker 1.11.1
͕Ͱͯͨ • ໌ࢼ͍ͨ͠ͱ͓͍·͢ 29 VASILY Inc. 2016
#3 Envoirnment clone • production/stagingͷڥΛ·ΔͬͱίϐʔͰ͖Δ • base platformΛมߋ͢Δࡍͷςετ 30 VASILY
Inc. 2016
#3 Envoirnment clone 31 VASILY Inc. 2016
#3 Envoirnment clone 32 VASILY Inc. 2016
#3 Envoirnment clone • ΫϦοΫͰίϐʔͰ͖ΔͷͰͱͯศར! 33 VASILY Inc. 2016
#4 auto-scaling • ௨ৗͷΞΫηε૿Ճ/ݮগʹAuto-ScalingͰରԠ • EBͷweb consoleͷScaling configurationͰઃఆ • Sum
RequestCountϕʔε 34 VASILY Inc. 2016
#5 Time Scheduled-based auto- scaling • ADωοτϫʔΫ • iQONҎ֎ͷΞϓϦʹ৴ 35
VASILY Inc. 2016
#5 Time Scheduled-based auto- scaling • ͱ͋ΔΞϓϦ͕pushΛ͏ͭ • spike͢Δ •
௨ৗͷauto-scalingͰ͍͔ͭͳ͍ • pushʹΑΔspike͕ऩ·ͬͨ͋ͱʹىಈྃ.. • ҙຯͳ͍ 36 VASILY Inc. 2016
#5 Time Scheduled-based auto- scaling • time scheduled base auto-scalingΛઃఆ
• web console͔ΒઃఆͰ͖ͳ͍ͷͰaws cliͰߦ͏ 37 VASILY Inc. 2016
#5 Time Scheduled-based auto- scaling • time scheduled base auto-scalingΛઃఆ
• scale out aws autoscaling put-scheduled-update-group-action \ --auto-scaling-group-name awseb-e-XXXXXX \ --scheduled-action-name ScaleOut \ --recurrence "00 10 * * *" \ --desired-capacity 10 \ --min-size 10 \ --max-size 12 38 VASILY Inc. 2016
#5 Time Scheduled-based auto- scaling • time scheduled base auto-scalingΛઃఆ
• scale in aws autoscaling put-scheduled-update-group-action \ --auto-scaling-group-name awseb-e-XXXXXX \ --scheduled-action-name ScaleIn \ --recurrence "30 16 * * *" \ --desired-capacity 6 \ --min-size 6 \ --max-size 8 39 VASILY Inc. 2016
#5 Time Scheduled-based auto- scaling • ઌํӡ༻͠ͳ͕ΒͩͬͨͷͰɺ͏·͍͘ͳ͔͍͜ͱଟ͔ͬ ͨ • ݱࡏpushͷӡ༻͕ͱ·ͬͨ
• time scheduled base auto scalingઃఆͯ͠ͳ͍ 40 VASILY Inc. 2016
#6 ։ൃڥ • docker-compose ͰproductionͱಉͷڥΛىಈͰ͖ΔΑ͏ʹ ͍ͯ͠Δ • mysql,redis,memcacheࣾ։ൃαʔόΛࢀর 41 VASILY
Inc. 2016
#6 ։ൃڥ • ීஈMBPͷruby,nginxͰ։ൃΛ͍ͯ͠Δ • ։ൃ࣌جຊతʹҰਓͰΈͯΔͷͰContainerͷྑ͍ॴ͕ग़ͤ ͳ͍.. • docker-compose run
app rake ͰCIͷΈ࣮ࢪ 42 VASILY Inc. 2016
#7 Docker build • DockerfileผrepositoryͰGithubͰཧ • docker resitory(quay.io)ͷbuild hookະ࠾༻ •
खݩͷMBP(docker-machine) Ͱdocker build & pushͰӡ༻ • docker build -t quay.io/vasilyjp/ruby:2.3.1-alpine . • docker push quay.io/vasilyjp/ruby:2.3.1-alpine 43 VASILY Inc. 2016
#7 Docker build • ad-serverͷ2ஈͷimageCircleCI͕build • ઐ༻ͷbranchʹpush͢ΔͱCircleCI͕build & push 44
VASILY Inc. 2016
#7 Docker build • alpineԽ͔ͯ͠ΒDockerfile͓͡͞ΜԽ͕ݦஶʹਐΜͰΔؾ͠ ·͢.. 45 VASILY Inc. 2016
োฤ • ओʹӡ༻ϛεʹΑΔো͕ൃੜ͠·ͨ͠ 46 VASILY Inc. 2016
#1 quay.ioύεϫʔυมߋʹ͏ deployͷࣦഊ • imageΛquay.ioͰϗετ • ϚελͷύεϫʔυΛͦͷ··deploy࣌ʹ͍ͬͯͨ • .dockercfgʹϚελΞΧϯτͷͷΛೖΕ͍ͯͨ 47
VASILY Inc. 2016
#1 quay.ioύεϫʔυมߋʹ͏ deployͷࣦഊ • μϝ! ઈର!! 48 VASILY Inc. 2016
#1 quay.ioύεϫʔυมߋʹ͏ deployͷࣦഊ • ϚελύεϫʔυͷมߋΛߦͬͨ • ͦͷޙͷσϓϩΠʹࣦഊ • docker pull͕Ͱ͖ͳ͘ͳͬͨ..
49 VASILY Inc. 2016
#1 quay.ioύεϫʔυมߋʹ͏ deployͷࣦഊ • auto-scalingͷλΠϛϯάͱ૬·ͬͯΞΧϯτ͕ϩοΫ • େྔͷdocker pullͷࣦഊ͕ൃੜ • ϚελͷΞΧϯτͰdocker
pull ͕ϩʔΧϧڥͰͰ͖ͳ͘ ͳͬͨ 50 VASILY Inc. 2016
#1 quay.ioύεϫʔυมߋʹ͏ deployͷࣦഊ • ରԠ • σϓϩΠ༻ͷϩϘοτΞΧϯτΛ࡞(quay.ioͷػೳ) • ͦͷޙɺোى͖͍ͯͳ͍ 51
VASILY Inc. 2016
#1 quay.ioύεϫʔυมߋʹ͏ deployͷࣦഊ • quay.io͕SPOFʹͳ͍ͬͯΔͷͰɺηΧϯμϦʹ͍ͭͯݕ౼த • ECRϦϦʔεॳʹ؆୯ʹςετͨ͠ͷΈ • ݟ͋Εڭ͑ͯԼ͍͞! 52
VASILY Inc. 2016
#2 mackerel-agentͷΞϥʔτ • mackerelͰࢹ • auto-scalingͰΧδϡΞϧʹinstance͕ࢭ·Δ • unreachableͷΞϥʔτ͕ඈͿ • unreachable
Ͱ͋Δ͚ͲɺোͰͳ͍.. 53 VASILY Inc. 2016
#2 mackerel-agentͷΞϥʔτ • auto-scalingͳڥ༻ͷઃఆΛ࡞ͬͯΒͬͨ 54 VASILY Inc. 2016
#2 mackerel-agentͷΞ ϥʔτ ಈ͔ͳ͔ͬͨ.. 55 VASILY Inc. 2016
#2 mackerel-agentͷΞϥʔτ • Ұ୴ɺରͷroleͷunreachableͷΞϥʔτઃఆΛͬͨ.. • ࢹͷҙຯ͕ແ͍.. 56 VASILY Inc. 2016
#2 mackerel-agentͷΞϥʔτ • base platformΛมߋͨ͠Β͏·͍͘͘Α͏ʹͳͬͨ • Amazon Linux 2015.09 v2.0.8
docker 1.9.1 • ڥʹΑͬͯtrap͕ಈ͍ͨΓಈ͔ͳ͔ͬͨΓͯ͠Δͱͷ͜ͱ.. • EBͰͷঢ়گQiitaʹॻ͍ͯ·͢ -> http://qiita.com/tknzk/items/a6b1a9003ff26683b88a 57 VASILY Inc. 2016
#3 كʹσϓϩΠʹࣦഊ͢Δ • deployϑϩʔ • CircleCIͰmasterͷbranchͷCI͕·ΘΔͱdeploy hook͕͠Δ • eb deploy
ad-server-prod 58 VASILY Inc. 2016
#3 كʹσϓϩΠʹࣦഊ͢Δ • deploy͕ࣦഊ͢Δ͕࣌͋Δ • mackerel-agentͷcontainerͷstopʹࣦഊ͢Δ͜ͱ͕͋Δ [ec2-user@ip-xx-xx-xxx ~]$ sudo docker
exec CONTAINER_ID ps axu nsenter: Unable to fork: Cannot allocate memory 59 VASILY Inc. 2016
#3 كʹσϓϩΠʹࣦഊ͢Δ • ෮چͰ͖ͳ͍ͷͰinstance͝ͱstopͯ͠ରԠ • mackerel-agentͷதͷͷΑ͏ͳؾ͕͍ͯ͠Δ͕ɺৄࡉ Ѳग़དྷ͍ͯͳ͍ 60 VASILY Inc.
2016
#3 كʹσϓϩΠʹࣦഊ͢Δ • deploy͕ࣦഊͨ͠Β • ΧδϡΞϧʹinstanceΛstopͯ͠ೖΕସ͑ • ࠶deploy 61 VASILY
Inc. 2016
#3 كʹσϓϩΠʹࣦഊ͢Δ • auto-scalingͷhealth-checkͷରΛELBʹ͢Δ • deployʹࣦഊͯ͠ELB͔ΒΓ͞Εͨঢ়ଶ • ߏʹͳ͍ͬͯΕͳ͘ӡ༻Ͱ͖Δ 62 VASILY
Inc. 2016
#4 awsebcli ʹΑΔσϓϩΠʹࣦഊ(Ұ ͖Γ) • deployCircleCI͔Β eb deploy ad-server-prod ͰσϓϩΠ
• applicationΛzipͨ͠ϑΝΠϧΛs3ʹput • ֤instance͕pullͯ͘͠Δ 63 VASILY Inc. 2016
#4 awsebcli ʹΑΔσϓϩΠʹࣦഊ(Ұ ͖Γ) • ಛఆͷawsebcli s3ʹpush͢ΔϑΝΠϧ໊͕gitͷcommithash 4 ܻͰݻఆ •
ຊ൪ӡ༻։࢝લʹੜͨ͠ϑΝΠϧ໊ͱconflictͯ͠deploy͕ί έͨ • ͜ͷ࣌ίέ͚͕ͨͩͩͬͨޭ͢ΔͱσάϨ͢Δ͜ͱʹͳͬ ͨ 64 VASILY Inc. 2016
#4 awsebcli ʹΑΔσϓϩΠʹࣦഊ(Ұ ͖Γ) • ݱ࣌ͰɺTimeStamp͕suffixͱͯͭ͘͠Α͏ʹͳͬͨ • versino 3.6.2 Ҏ߱
65 VASILY Inc. 2016
#4 awsebcli ʹΑΔσϓϩΠʹࣦഊ(Ұ ͖Γ) • ఆظతʹapplication versionsͷͱ͜Ζʹ͋ΔϑΝΠϧΛআ • σϑΥϧτ500·Ͱอ࣋Ͱ͖Δ •
ݹ͍ͷΛ͍ͯͯ͋͠·Γҙຯͳ͍ͷͰফͯ͠Δ 66 VASILY Inc. 2016
Conclusion • 1ؒ EB w/multi-container docker Ͱӡ༻ͯ͠ى͖ͨ͜ͱΛ͓ ͠·ͨ͠ • ӡ༻ϛεʹΑΔো͋Γ·͕ͨ͠ɺEBdockerʹىҼ͢Δো
ͳ͠ • alpine linuxΛproductionͰӡ༻தͰ͢ • iQONຊମͷAPI͍ͣΕ... 67 VASILY Inc. 2016
We are hiring! •
[email protected]
68 VASILY Inc. 2016
end ͋Γ͕ͱ͏͍͟͝·ͨ͠ 69 VASILY Inc. 2016