Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
eb_with_multi_container_docker
Search
Takumi KANZAKI
June 27, 2016
Technology
2.5k
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
eb_with_multi_container_docker
# JAWS-UGおコンテナ支部 #5
- EB with multi-container Docker をproductionで1年間運用して起きたこと
Takumi KANZAKI
June 27, 2016
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.3k
kosodate_engineer_meetup_2
tknzk
3
6.2k
AdServer Casual Monitoring by fluentd, Mackerel
tknzk
0
1.9k
Other Decks in Technology
See All in Technology
Obsidian Vault Architectures
x5gtrn
PRO
0
230
AI AgentによるEmbedded SREの取り組み
tgidgd
1
310
なぜ東京にいる私が、新潟の技術コミュニティを運営するのか by 八雲慎之助
yakumo
0
210
Flutter Widget Previewerで始めるUIプレビューとVRTの自動化
sakusaku3939
0
190
AI時代、つくる力を自分たちの手に。 ──電通×KAG、アジャイルとAI駆動開発で挑む開発の変革
yuukiyo
3
450
1週間、Opus封印でお願いします
kintotechdev
1
420
E2Eってつらくないですか?E2Eの管理コストを下げる手段とその実践
akaboshinit
6
2.9k
AIエージェント統制はAPIから——押さえるべき5つの要素
nagix
0
110
20261031_IoTLT_vol140_kitazaki_v1.pdf
kitazaki
0
150
Devin プロモコードの受け取りと適用(2026.10.27)
kinopeee
1
790
Snowflake でできることが増えたら、 ABAC が必要になった
kaeton
0
130
視野はAIに、視座は人に / ai-for-breadth-humans-for-perspective
nkzn
6
2.7k
Featured
See All Featured
GitHub's CSS Performance
jonrohan
1033
470k
The #1 spot is gone: here's how to win anyway
tamaranovitovic
4
1.2k
Crafting Experiences
bethany
1
400
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
46
3k
Jess Joyce - The Pitfalls of Following Frameworks
techseoconnect
PRO
1
460
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
10
1.4k
Bioeconomy Workshop: Dr. Julius Ecuru, Opportunities for a Bioeconomy in West Africa
akademiya2063
PRO
1
430
SERP Conf. Vienna - Web Accessibility: Optimizing for Inclusivity and SEO
sarafernandez
2
1.6k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
508
140k
How To Stay Up To Date on Web Technology
chriscoyier
790
250k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
133
20k
Navigating Team Friction
lara
192
16k
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