Slide 1

Slide 1 text

&$4Λར༻ͨ͠σϓϩΠ؀ڥ ,PIFJ4V[VLJ

Slide 2

Slide 2 text

.F • @eagletmt • ΫοΫύου ٕज़෦։ൃج൫άϧʔϓ • Docker Λར༻ͨ͠ΞϓϦέʔγϣϯαʔόج൫ͷ ։ൃɺӡ༻

Slide 3

Slide 3 text

Ξ΢τϥΠϯ • ΫοΫύουͱ Docker • Docker ΞϓϦͷσϓϩΠํ๏ v1 • ECS ҎલͷσϓϩΠํ๏ • Docker ΞϓϦͷσϓϩΠํ๏ v2 • ECS Λར༻ͨ͠σϓϩΠπʔϧ Hako ͷ։ൃ • Hako Λ࢖ͬͨσϓϩΠ؀ڥ

Slide 4

Slide 4 text

ΫοΫύουͱ%PDLFS • 2014೥9݄ࠒ͔Β Docker ͷར༻Λݕ౼ • ࣗ෼͕৽نʹ։ൃ͢Δখ͍͞ Web API ΞϓϦέʔ γϣϯΛύΠϩοτϓϩδΣΫτͱ͠ɺ12݄͔Βར ༻։࢝

Slide 5

Slide 5 text

ΫοΫύουͱ%PDLFS • 2015೥͔Βɺ৽نͷ Web ΞϓϦέʔγϣϯ͸جຊ తʹ Docker Λར༻ͨ͠؀ڥ (v1) Ͱಈ࡞ • 2016೥6݄ݱ࣌఺ʹ͓͍ͯɺ • ຊ൪Քಈ͍ͯ͠ΔαʔϏε͕ 11 ݸ • εςʔδϯά༻్ʹ 14 ݸ • ࣾ಺αʔϏεʹ 8 ݸ

Slide 6

Slide 6 text

ΫοΫύουͱ%PDLFS • 2015೥9݄ࠒ͔Β ECS Λར༻ͨ͠৽ߏ੒ (v2) Λݕ౼ • 2016೥1݄͔Βࣾ಺αʔϏεͰར༻։࢝ • 5݄͔Βຊ൪Ͱ΋ར༻։࢝͠ɺݱ࣌఺Ͱ • ຊ൪Քಈ͍ͯ͠ΔαʔϏε͕ 2 ݸ • εςʔδϯά༻్ʹ 10 ݸ • ࣾ಺αʔϏεʹ 21 ݸ

Slide 7

Slide 7 text

%PDLFSΞϓϦͷσϓϩΠ ํ๏W

Slide 8

Slide 8 text

&$4Λ࢖͍࢝ΊΔલ • σϓϩΠํ๏Λߟ͑ɺϗετଆʹσϓϩΠεΫϦϓτ Λ༻ҙ͢Δ͜ͱʹͨ͠ • ඞཁͳ͜ͱ • Web ΞϓϦέʔγϣϯͷσϓϩΠΛແఀࢭͰߦ͏ • σϓϩΠ͸શ։ൃऀ͕ߦ͏͜ͱ͕Ͱ͖Δ • ։ൃऀʹ͸ൿಗ஋ (DB ύεϫʔυͳͲ) Λݟͤͳ͍ • ൿಗ஋͸؀ڥม਺ͱͯ͠౉͢

Slide 9

Slide 9 text

σϓϩΠํ๏ W • 1ͭͷϗετʹ1ͭ·ͨ͸ෳ਺ͷ Docker ίϯςφ • ϗετଆʹ nginx Λ1ͭىಈ͠ɺHost ϔομͰίϯςφ ʹৼΓ෼͚ • σϓϩΠ࣌͸ɺίϯςφΛ৽نʹىಈ͠ɺnginx ͷઃఆ Λมߋͯ͠Ϧϩʔυ͠ɺݹ͍ίϯςφΛఀࢭ͢Δ • ৄ͘͠͸ http://techlife.cookpad.com/entry/ 2015/04/20/134758

Slide 10

Slide 10 text

σϓϩΠํ๏ W OHJOY BQQTFSWFS DPOUBJOFS W EFQMPZTDSJQU

Slide 11

Slide 11 text

σϓϩΠํ๏ W OHJOY BQQTFSWFS DPOUBJOFS W DPOUBJOFS W EFQMPZTDSJQU docker run

Slide 12

Slide 12 text

σϓϩΠํ๏ W OHJOY BQQTFSWFS DPOUBJOFS W DPOUBJOFS W EFQMPZTDSJQU IFBMUIDIFDL

Slide 13

Slide 13 text

σϓϩΠํ๏ W OHJOY BQQTFSWFS DPOUBJOFS W DPOUBJOFS W EFQMPZTDSJQU nginx -s reload

Slide 14

Slide 14 text

σϓϩΠํ๏ W OHJOY BQQTFSWFS DPOUBJOFS W EFQMPZTDSJQU docker stop

Slide 15

Slide 15 text

WͷΑ͔ͬͨ఺ • Πϯϑϥ͕ Itamae ͰΞϓϦέʔγϣϯຖʹϓϩϏ δϣχϯά͢Δख͕ؒͳ͘ͳͬͨ • ڞ௨ͷϗετͷ্ʹ༷ʑͳίϯςφ͕ಈ͘ • ΞϓϦέʔγϣϯαʔόͷΦʔτεέʔϧ͕͠΍͢ ͘ͳͬͨ • શ͘ಉ͡ํ๏ͰɺͲΜͳΞϓϦέʔγϣϯ΋εέʔ ϧΠϯɾεέʔϧΞ΢τͰ͖Δ

Slide 16

Slide 16 text

Wͷ࢒೦ͩͬͨ఺ • σϓϩΠઌͷϗετͷࢦఆ͕ਓྗ • EC2 λάʹࢦఆ͍ͯͨ͠ • ৽نͷαʔϏεΛ௥Ճ͢Δͱ͖͸ɺۭ͍ͯͦ͏ͳΠϯε λϯεʹλάΛ͚ͭΔ͔ɺ৽نʹىಈ͢Δඞཁ͕͋ͬͨ • ΞϓϦέʔγϣϯαʔόҎ֎ʹ΋ඞཁͳ΋ͷ͸͋Δ • RDSɺRoute53ɺELBɺCapistrano ͷઃఆ • ؀ڥม਺ͷ௥Ճ

Slide 17

Slide 17 text

%PDLFSΞϓϦͷσϓϩΠ ํ๏W

Slide 18

Slide 18 text

&$4Խ • ECS Λར༻͢Δ͜ͱͰɺσϓϩΠઌͷ੍ޚΛ೚ͤ Δ͜ͱ͕Ͱ͖Δ • EC2 λά͔Βͷղ์ • ECS Խʹ͋ͨͬͯൿಗ஋ͷѻ͍Λߟ͑Δ • task definition ͸Ӆͭͭ͠ɺผͷετϨʔδ͔Β ൿಗ஋Λ஫ೖ͢Δඞཁ͕͋Δ

Slide 19

Slide 19 text

&$4Խ • Route53 ΍ͦͷଞͷઃఆ͸ ECS ͚ͩͰ͸׬݁͠ͳ ͍ • ECS Λར༻ͭͭ͠ɺൿಗ஋ͷ஫ೖ΍ؔ࿈͢ΔϦιʔ ε΍ઃఆΛૢ࡞͢ΔσϓϩΠπʔϧ͕ඞཁ • => Hako ͷ։ൃ

Slide 20

Slide 20 text

)BLP • Docker ίϯςφΛσϓϩΠ͢ΔͨΊͷπʔϧ • ࠓͷͱ͜Ζ ECS ͷΈʹରԠ • ΞϓϦέʔγϣϯͷఆٛΛ YAML Ͱهड़ • ൿಗ஋ΛؚΉ؀ڥม਺Λѻ͑Δ • σϓϩΠ࣌ʹ༷ʑͳॲཧΛࠩ͠ࠐΉ͜ͱ͕Ͱ͖Δ

Slide 21

Slide 21 text

ઃܭϙϦγʔ • Ͱ͖Δ͚ͩ੩తͳఆٛʹ͢Δ • ఆٛ (ઃఆ) ͸ YAML Ͱɺίʔυ͸ Ruby Ͱ • ఆٛ͸ͦͷ··ͰɺRuby Ҏ֎Ͱ΋࣮૷Ͱ͖Δܗ • ϓϥΨϒϧʹ͢Δ • Docker ʹඞཁͳ΋ͷͷΈίΞʹؚΊΔ • ͦΕҎ֎ͷίʔυ͸ϓϥάΠϯͱͯࠩ͠͠ସ͑Մೳʹ ͢Δ

Slide 22

Slide 22 text

ΞϓϦέʔγϣϯఆٛ scheduler: <<: !include schedulers/internal_default.yml desired_count: 1 app: image: 01234567890.dkr.ecr.us-east-1.amazonaws.com/camo cpu: 128 memory: 128 port: 8080 env: $providers: - <<: !include env_providers/etcenv.yml root: /envs/hako/camo CAMO_KEY: '#{CAMO_KEY}' CAMO_KEEP_ALIVE: 'true' additional_containers: front: !include containers/front.yml consul-register: !include containers/consul_register_internal.yml scripts: - type: jenkins_tag job: docker-camo - !include scripts/route53_subdomain_shared.yml - !include scripts/nginx_omniauth.yml - type: consul_register

Slide 23

Slide 23 text

σϓϩΠํ๏ W • Hako::Schedulers::Ecs • ECS ্ʹ serviceɺtask definitionɺELB Λ࡞੒ • σϓϩΠ࣌ʹ͸ɺtask definition ͱ service Λߋ৽ • ͓ͦΒ͘ ECS ͷී௨ͷ࢖͍ํ

Slide 24

Slide 24 text

σϓϩΠํ๏ W • YAML ͷఆٛͱ DescribeTaskDefinition ͷ݁ՌΛൺ ֱ • ඞཁʹԠͯ͡ RegisterTaskDefinition Ͱߋ৽ • CreateService / UpdateService Ͱࢦ͍ͯ͠Δ task definition Λߋ৽ • CreateService ࣌ʹ͸ ELB ΋࡞੒͢Δ

Slide 25

Slide 25 text

σϓϩΠํ๏ W &-# UBTLW TFSWJDF IBLP

Slide 26

Slide 26 text

σϓϩΠํ๏ W &-# UBTLW UBTLW TFSWJDF IBLP 3FHJTUFS5BTL%FpOJUJPO 6QEBUF4FSWJDF

Slide 27

Slide 27 text

σϓϩΠํ๏ W &-# UBTLW TFSWJDF IBLP

Slide 28

Slide 28 text

σϓϩΠํ๏ W ࣾ಺αʔϏε൛ • ͜ͷํ๏ͩͱ service ຖʹ ELB ͕ඞཁ • ࣾ಺޲͚ͷࡶαʔϏεͰ΋ຖճ ELB Λ࡞Δ…? • ڞ௨ͷ ELB Λ࢖͍ͭͭɺϦόʔεϓϩΩγͷઃఆΛ ͍͍͔Μ͡ʹมߋ͢ΔΑ͏ͳผͷϞʔυΛ࣮૷ • ࣾ಺ͷผͷج൫ʹґଘ͍ͯ͠ΔͷͰίʔυ͸ඇެ։ • Hako ͳΒσϓϩΠ෦෼͚ͩࠩ͠ସ͑Δ͜ͱ͕Մೳ

Slide 29

Slide 29 text

શମߏ੒ W ࣾ಺αʔϏε൛ OHJOY &-# UBTL UBTL UBTL UBTL SFWFSTFQSPYZ DPOUBJOFS JOTUBODFT

Slide 30

Slide 30 text

σϓϩΠํ๏ W ࣾ಺αʔϏε൛ OHJOY UBTLW DPOTVM IBLP TFSWJDFW

Slide 31

Slide 31 text

σϓϩΠํ๏ W ࣾ಺αʔϏε൛ OHJOY UBTLW DPOTVM IBLP TFSWJDFW UBTLW TFSWJDFW 3FHJTUFS5BTL%FpOJUJPO $SFBUF4FSWJDF

Slide 32

Slide 32 text

σϓϩΠํ๏ W ࣾ಺αʔϏε൛ OHJOY UBTLW DPOTVM IBLP TFSWJDFW UBTLW TFSWJDFW SFHJTUFS

Slide 33

Slide 33 text

σϓϩΠํ๏ W ࣾ಺αʔϏε൛ OHJOY UBTLW DPOTVM IBLP TFSWJDFW UBTLW TFSWJDFW DPOTVMUFNQMBUF nginx -s reload

Slide 34

Slide 34 text

σϓϩΠํ๏ W ࣾ಺αʔϏε൛ OHJOY DPOTVM IBLP UBTLW TFSWJDFW %FMFUF4FSWJDF EFSFHJTUFS DPOTVMUFNQMBUF nginx -s reload

Slide 35

Slide 35 text

ൿಗ஋ͷѻ͍ • ؀ڥม਺ʹม਺ͷΑ͏ʹຒΊࠐΉ͜ͱ͕Ͱ͖Δ • DATABASE_URL: 'mysql2://#{user}:#{pass}@db- nanika-001/nanika' • ม਺͸σϓϩΠ࣌ʹผͷετϨʔδ͔Βऔಘ • ͨͱ͑͹ etcenv Λ࢖͏৔߹ • https://github.com/eagletmt/hako-etcenv • user ͷ৔ॴʹ /hako/nanika/user ͷ஋͕ೖΔ

Slide 36

Slide 36 text

)BLPΛ࢖ͬͨ σϓϩΠ؀ڥ

Slide 37

Slide 37 text

)BLPΛ࢖ͬͨσϓϩΠ؀ڥ • ΞϓϦέʔγϣϯఆ͚ٛͩΛؚΉϦϙδτϦ hako_apps Λ༻ҙ • ؀ڥม਺ͳͲΛมߋ͍ͨ͠ͱ͖͸ɺ։ൃऀ͕ࣗ༝ʹ pull-requestɺmerge • ൿಗ஋Λ௥Ճ͍ͨ͠ͱ͖ͷΈΠϯϑϥʹґཔ

Slide 38

Slide 38 text

)BLPΛ࢖ͬͨσϓϩΠ؀ڥ • σϓϩΠίϚϯυͷ࣮ߦʹ͸ Rundeck Λར༻ • app αʔόͰ࣮ߦ͢ΔίϚϯυ͕ແ͍ͷͰɺ Capistrano Λ࢖͏ඞཁ͕ͳ͍ • Rundeck ্ͰδϣϒΛ࣮ߦ͢Δͱɺ • git clone git@repository:hako_apps.git • cd hako_apps && hako deploy nanika.yml

Slide 39

Slide 39 text

όονॲཧ • hako oneshot Ͱ service Λ࢖ΘͣʹɺRunTask Ͱ୯ ൃͷλεΫΛ࣮ߦͰ͖Δ • ࣾ಺Ͱ͸ kuroko2 ͷλεΫͱ࣮ͯ͠ߦͰ͖ΔΑ͏ʹ ੔උ • kuroko2 ʹ͍ͭͯ͸ http://techlife.cookpad.com/ entry/2015/12/07/195732

Slide 40

Slide 40 text

σϓϩΠ࣌ͷϑοΫ • Hako Ͱ͸ script ͱݺশ • σϓϩΠ࣌ʹ΍ͬͯΔ͜ͱ • Route53 ͷࣗಈઃఆ • nginx ίϯςφͷΞΫηε੍ݶͷઃఆ • σϓϩΠ͢ΔΠϝʔδͷϦϏδϣϯΛ Jenkins ͷ݁Ռ ͔Βܾఆ • ౳ʑ

Slide 41

Slide 41 text

Φʔτεέʔϧ • AutoScaling Group Λར༻͠ɺΫϥελ͝ͱʹΠϯ ελϯεΛ૿ݮͰ͖ΔΑ͏ʹ • ࠓͷͱ͜ΖεέʔϧΠϯ͸ͤͣɺσϓϩΠ࣌ (service ͷ࡞੒ɺߋ৽࣌) ʹΠϯελϯεͷΩϟύ γςΟ͕଍Γͯͳ͔ͬͨΒɺAutoScaling Group ͷ ΩϟύγςΟΛ্͛ͯεέʔϧΞ΢τ

Slide 42

Slide 42 text

ϩΪϯά • Docker ͷ log driver ΛࢦఆͰ͖Δ • fluentd log driver Λ࢖ͬͯɺϗετଆʹ fluentd Λཱͯ ͯɺ͔ͦ͜Β CloudWatch Logs ΁సૹ • service ໊΍ίϯςφ໊Λ log stream ͷ໊લʹؚΊΔ Α͏ʹ͍ͯ͠Δ • ద౰ͳΞϓϦͰαʔϏε͝ͱʹϩάΛӾཡͰ͖ΔΑ͏ʹ

Slide 43

Slide 43 text

)BLPʹͳͬͯΑ͔ͬͨ఺ • ΠϯελϯεΛखಈͰ࡞੒͠ͳͯ͘Α͍ • AutoScaling Group ͷΩϟύγςΟΛ૿΍͚ͩ͢ • ΞϓϦέʔγϣϯͷఆٛΛɺ։ൃऀ͕ࣗ༝ʹӾཡɾߋ৽ Ͱ͖ΔΑ͏ʹͳͬͨ • ґཔͰ͸ͳ͘ pull-request ʹ • Route 53 ͷઃఆͳͲɺయܕతͳ࡞ۀΛࣗಈԽͰ͖ͨ • ݁Ռɺؾܰʹࣾ಺ΞϓϦ͕࡞ΒΕΔΑ͏ʹͳͬͨ

Slide 44

Slide 44 text

ࠓޙͷల๬ • ϩΪϯάΛվળ͍ͨ͠ • ΞϓϦέʔγϣϯͷϩάΛଈ࠲ʹ֬ೝ͍ͨ͠ͱ͖ ͕͋Δ͕ɺݱঢ়Ͱ͖͍ͯͳ͍ • CloudWatch Logs ʹอଘ͢Δͷ͸ͦͷ··Ͱɺಉ ࣌ʹ଎ใΛϩʔΧϧϑΝΠϧʹॻ͘Α͏ʹ͢Δ?

Slide 45

Slide 45 text

ࠓޙͷల๬ • ECS Ҏ֎ͷαϙʔτ? • ͪΐ͏ͲઌिɺDocker 1.12 Ͱ orchestration ػೳ ͷڧԽ͕ൃද͞Εͨ • ͜ͷ service Λ Hako ͔Β੍ޚͰ͖ΔͱΑͦ͞͏ • https://blog.docker.com/2016/06/docker-1-12- built-in-orchestration/