Lock in $30 Savings on PRO—Offer Ends Soon! ⏳
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.4k
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
2.3k
新生児〜生後6ヶ月を支えた技術/kosodate-engineer-meetup-3
tknzk
4
2.2k
kosodate_engineer_meetup_2
tknzk
3
5.9k
AdServer Casual Monitoring by fluentd, Mackerel
tknzk
0
1.8k
Other Decks in Technology
See All in Technology
PostgreSQL で列データ”ファイル”を利用する ~Arrow/Parquet を統合したデータベースの作成~
kaigai
0
180
信頼性が求められる業務のAIAgentのアーキテクチャ設計の勘所と課題
miyatakoji
0
190
国産クラウドを支える設計とチームの変遷 “技術・組織・ミッション”
kazeburo
6
10k
Data Hubグループ 紹介資料
sansan33
PRO
0
2.3k
Codeer.LowCode.Blazor 紹介と成長録
wadawada
0
110
雲勉LT_Amazon Bedrock AgentCoreを知りAIエージェントに入門しよう!
ymae
2
230
巨大モノリスのリプレイス──機能整理とハイブリッドアーキテクチャで挑んだ再構築戦略
zozotech
PRO
0
400
Kill the Vibe?Architecture in the age of AI
stoth
1
120
都市スケールAR制作で気をつけること
segur
0
210
LangChain v1.0にトライ~ AIエージェントアプリの移行(v0.3 → v1.0) ~
happysamurai294
0
110
履歴テーブル、今回はこう作りました 〜 Delegated Types編 〜 / How We Built Our History Table This Time — With Delegated Types
moznion
10
7.1k
SRE視点で振り返るメルカリのアーキテクチャ変遷と普遍的な考え
foostan
2
3k
Featured
See All Featured
4 Signs Your Business is Dying
shpigford
186
22k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
127
54k
Rebuilding a faster, lazier Slack
samanthasiow
84
9.3k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
162
15k
Designing for humans not robots
tammielis
254
26k
Designing Experiences People Love
moore
142
24k
Reflections from 52 weeks, 52 projects
jeffersonlam
355
21k
How Fast Is Fast Enough? [PerfNow 2025]
tammyeverts
3
350
StorybookのUI Testing Handbookを読んだ
zakiyama
31
6.4k
What's in a price? How to price your products and services
michaelherold
246
12k
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
4.1k
Raft: Consensus for Rubyists
vanstee
140
7.2k
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