Slide 1

Slide 1 text

όονΞϓϦͷӡ༻ج൫Λ&$4΁Ҡߦ͢Δ࿩ 2016/09/09 M3 tech meetup! #3 #m3sushi @yukiyan_w

Slide 2

Slide 2 text

Who? ʙ4*FS ʙGFFEGPSDF*OD "QQMJDBUJPO&OHJOFFS όονɾ$47ɾ3VCZΛओʹ৮Δɻ Ώ͖΍Μ @yukiyan_w http://yukiyan.hatenablog.jp/

Slide 3

Slide 3 text

Introduction લஔ͖ ׬શҠߦ͸·ͩͰ͖͍ͯͳ͍

Slide 4

Slide 4 text

Introduction લஔ͖ %PDLFSJ[F΍&$4Խ͸ɺ݄͘Β͍ʹ࢝Ίͨ

Slide 5

Slide 5 text

Introduction લஔ͖ ͜͜ϲ݄Ͱ΍ͬͨ͜ͱΛ࿩͠·͢

Slide 6

Slide 6 text

Introduction લஔ͖ ࣌ؒͷ౎߹্ɺ͍ͩͿ಺༰Λ࡟ͬͨͷͰ ͋ͱͰิ଍هࣄॻ͖·͢

Slide 7

Slide 7 text

Introduction લఏ஌ࣝ ͲΜͳόονΛ૸Β͍ͤͯΔͷ͔ʁ

Slide 8

Slide 8 text

Introduction લఏ஌ࣝ $47Λड͚औΓɺม׵ॲཧΛࢪ͢όον

Slide 9

Slide 9 text

Introduction લఏ஌ࣝ &$4ͱ͸ʁ

Slide 10

Slide 10 text

Introduction લఏ஌ࣝ ߴੑೳͳίϯςφ؅ཧαʔϏε

Slide 11

Slide 11 text

Introduction લఏ஌ࣝ &$ΠϯελϯεΛऔΓ·ͱΊͯ؅ཧ্ͨ͠Ͱɺ ͋Β͔͡ΊఆΊͨ௨ΓʹίϯςφΛάϦάϦಈ͔ͨ͢Ίͷ ϚωʔδυαʔϏε

Slide 12

Slide 12 text

Table Of Contents Agenda ݱঢ় 1 2 ਐΊํ 3 ؾΛ͚ͭͨ͜ͱ 4 ͭΒ͔ͬͨ͜ͱ 5 ·ͱΊ 6 ໨ࢦ͢΋ͷ

Slide 13

Slide 13 text

ݱঢ়

Slide 14

Slide 14 text

ݱঢ় αʔόߏ੒ਤ ˞Ұ෦ׂѪ 3BJMTΞϓϦ %#ແ͠

Slide 15

Slide 15 text

ݱঢ় εέʔϧ͢ΔͱͭΒ͘ͳΔ ɾDSPOTFSWFS͕410' ɾෛՙ͕ෆۉߧ Ջͳαʔό͕͋Δ ɾखಈεέʔϧ

Slide 16

Slide 16 text

໨ࢦ͢΋ͷ

Slide 17

Slide 17 text

໨ࢦ͢΋ͷ ΄ͬͱ͍͓͚ͯΔঢ়ଶ ˞ఆ࣮࣌ߦ͸MBNCEBʹ೚ͤΔ

Slide 18

Slide 18 text

໨ࢦ͢΋ͷ ྑ͘ͳΔ͜ͱ ɾδϣϒ͕Ͳ͜Ͱಈ͔͘ؾʹ͠ͳͯ͘Α͘ͳΔ ɾϦιʔε͕༨ͬͯΔΠϯελϯεͰ࣮ߦ͞ΕΔ ɾ଍Γͳ͘ͳͬͨΒΦʔτεέʔϧ

Slide 19

Slide 19 text

ਐΊํ

Slide 20

Slide 20 text

ਐΊํ ։ൃମ੍ Engineer Leader Engineer Engineer  !  %PDLFSৄ͍͠ %PDLFSॳ৺ऀ ೥৽ଔೖࣾ %PDLFSॳ৺ऀ શһ"QQMJDBUJPO&OHJOFFS

Slide 21

Slide 21 text

%PDLFSॳ৺ऀूஂʜ

Slide 22

Slide 22 text

৽ਓ΋͍Δ͚Ͳʜ

Slide 23

Slide 23 text

ڭҭίετ͸੎͍ͰΧόʔ

Slide 24

Slide 24 text

ࢿྉ΋๛෋ͩ͠վΊͯڭҭ͢Δඞཁͳ͍Ͱ͠ΐ

Slide 25

Slide 25 text

ڧؾͷ࢟੎

Slide 26

Slide 26 text

ڧؾͷ࢟੎

Slide 27

Slide 27 text

੎͍ͷ͋Δ৽ਓ IUUQCJUMZD3L:J

Slide 28

Slide 28 text

ۀ຿࣌ؒ֎ͳͷʹͳ͔ͥଈϨε

Slide 29

Slide 29 text

ؾ͍ͮͨΒΈΜͳৄ͘͠ͳͬͯͨ

Slide 30

Slide 30 text

೔ʹ೔ʹৄ͘͠ͳ͍ͬͯ͘ਤ

Slide 31

Slide 31 text

ਐΊํ &$4ԽΛͲͷΑ͏ʹਐΊ͍͔ͯͬͨ ։ൃ؀ڥͷDockerԽ ɾDockerize ɾdocker-compose ECS؀ڥͷߏங ɾrun-taskͰδϣϒ࣮ߦ ɾCircleCI੔උ ӡ༻४උ ɾAutoscaling ruleߟ͑Δ ɾmackerel ɾͦͷଞʢlambdaͱ͔ʣ ׬શҠߦ ɾঃʑʹҠߦ ↑ ΠϚίίͷ։ൃத ↑ ίίϚσ࿩͢

Slide 32

Slide 32 text

ਐΊํ։ൃ؀ڥͷ%PDLFSԽ %PDLFSJ[F FROM centos:6.8 FROM fluent/fluentd:v0.12.26-onbuild FROM centos:6.8

Slide 33

Slide 33 text

ਐΊํ։ൃ؀ڥͷ%PDLFSԽ %PDLFSJ[F %PDLFS*NBHFͷμΠΤοτ͸͋ͱ·Θ͠

Slide 34

Slide 34 text

ਐΊํ։ൃ؀ڥͷ%PDLFSԽ %PDLFSJ[F ૫ͤΑ͏ͱ͢Δҙࢥ͸͋Δ

Slide 35

Slide 35 text

ਐΊํ։ൃ؀ڥͷ%PDLFSԽ EPDLFSDPNQPTFΛ࢖͏ ϩʔΧϧͰಈ࡞֬ೝ͕͠΍͍͢

Slide 36

Slide 36 text

ਐΊํ&$4؀ڥͷߏங &$4Ϋϥελ͸։ൃϝϯόʔ෼༻ҙ ։ൃϝϯόʔ༻QSPEVDUJPO༻ͭ ಈ࡞֬ೝ͕͠΍͍͢ɻؾܰʹࢼͤΔͷͰཧղ΋ਂ·Δɻ &$4ʹؔ͢Δݕূ͸֤ࣗΑΖ͘͠΍ͬͯ΋Β͏ɻ

Slide 37

Slide 37 text

ਐΊํ&$4؀ڥͷߏங &$4Ϋϥελ͸։ൃϝϯόʔ෼༻ҙ 6TFSEBUB͸͜Μͳײ͡ lib/tasks/aws/production.rake lib/tasks/aws/sandbox.rake

Slide 38

Slide 38 text

ਐΊํ&$4؀ڥͷߏங 5BTLEFGJOJUJPOͷߏ੒ CBUDI༻

Slide 39

Slide 39 text

ਐΊํ&$4؀ڥͷߏங 5BTLEFGJOJUJPOͷߏ੒ GMVFOUE༻

Slide 40

Slide 40 text

ਐΊํ&$4؀ڥͷߏங 5BTLͷߏ੒ ͖ͬ͞ͷ5BTLEFGJOJUJPO͕͜͏ͳΔ Docker container Docker container Docker container batch༻ Task fluentd༻ Task

Slide 41

Slide 41 text

ਐΊํ&$4؀ڥͷߏங &$4্Ͱ͸͜͏ͳΔ GMVFOUE༻5BTL͕4FSWJDFͱͯ͠ৗ࣌Քಇ͍ͯ͠Δ ECS Cluster Internal CLB EC2 ECS Agent Task Service EC2 ECS Agent Task Service EC2 ECS Agent EC2 ECS Agent :24224 :24224 "desiredCount": 2, "deploymentConfiguration": { "maximumPercent": 200, "minimumHealthyPercent": 100 } http://bit.ly/2clQnv5

Slide 42

Slide 42 text

ਐΊํ&$4؀ڥͷߏங &$4Ͱͷߏ੒ SVOUBTL͢ΔͱCBUDI͕૸Δ ECS Cluster Internal CLB EC2 ECS Agent Task Service EC2 ECS Agent Task Service EC2 ECS Agent EC2 ECS Agent :24224 :24224 ECS Scheduler batch Task

Slide 43

Slide 43 text

ਐΊํ&$4؀ڥͷߏங &$4Ͱͷߏ੒ &-#Λ࢖ͬͨ4FSWJDFEJTDPWFSZ ECS Cluster Internal CLB EC2 ECS Agent Task Service EC2 ECS Agent Task Service EC2 ECS Agent EC2 ECS Agent :24224 :24224 ECS Scheduler batch Task sandbox-wakayama.vpclocal:24224 "logDriver": "fluentd", "options": { "tag": “docker.batch-app", "fluentd-address": “sandbox-wakayama.vpclocal:24224" }

Slide 44

Slide 44 text

ਐΊํ&$4؀ڥͷߏங $JSDMF$*ܦ༝ͰͷϗοτσϓϩΠ ϚʔδΛϑοΫʹίϯςφ͕σϓϩΠ͞ΕΔ deploy aws ecs update-service Serverspec bundle exec rake serverspec RSpec bundle exec rake spec ! git merge topic branchΛϚʔδ CircleCI workflow hot deploy via CircleCI " ECR docker push

Slide 45

Slide 45 text

ؾΛ͚ͭͨ͜ͱ

Slide 46

Slide 46 text

ؾΛ͚ͭͨ͜ͱ %PDLFSGJMF͸Ͱ͖Δ͚ͩಡΈ΍͘͢͢Δ ൿ఻ͷλϨԽΛ๷͙ɻ

Slide 47

Slide 47 text

lazͰฒ΂Δ΍ͭ গ͠Ͱ΋ಡΈ΍͘͢ͳΔΑ͏ʹɻ

Slide 48

Slide 48 text

ґଘੑͷ͋ΔQBDLBHF͸&/7ʹࢦఆͯ͠͠·͏ ʮ͜ΕͬͯͳΜͷͨΊʹೖΕͯΜͷʁʯͷ๷ࢭ

Slide 49

Slide 49 text

ؾΛ͚ͭͨ͜ͱ ࢖͍͍ͨϩάυϥΠό͸6TFSEBUBʹॻ͔ͳ͍ͱ࢖͑ͳ͍ &$4"HFOUͷઃఆ

Slide 50

Slide 50 text

σϑΥϧτ͸[“json-file"]ͷΈɻ໘౗ͳͷͰશ෦ॻ͍ͨɻ https://docs.aws.amazon.com/ja_jp/AmazonECS/latest/developerguide/ecs-agent-config.html

Slide 51

Slide 51 text

ͭΒ͔ͬͨ͜ͱ

Slide 52

Slide 52 text

஌ݟ ͭΒ͔ͬͨ͜ͱ ίϯςφͷ؀ڥม਺ͷ੾Γସ͑

Slide 53

Slide 53 text

EPDLFSGJMFTGMVFOUEFYQPSU@FOWGJMFTI EPDLFSGJMFTGMVFOUE%PDLFSGJMF &OUSZLJUͷTXJUDIͰؤுΔελΠϧ ൿಗ஋ΛؚΜͰ͍ΔͷͰ4͔Βऔ͖͍ͬͯͯΔ 44&ࡁΈ

Slide 54

Slide 54 text

஌ݟ ͭΒ͔ͬͨ͜ͱ $JSDMF$*ͰΩϟογϡ͕ޮ͔ͳ͍ dockerfileͷfull build͕ຖճ૸Δɻ load/saveํࣜͰͰ͖Δͱॻ͍ͯ͋Δ͕ɺͦΕͰ΋Ωϟογϡ͞Εͳ͍ɻ ɾhttps://circleci.com/docs/docker/#caching-docker-layers

Slide 55

Slide 55 text

஌ݟ ͭΒ͔ͬͨ͜ͱ "-#࢖͑ͳ͔ͬͨ Service discoveryʹCLBΛ࢖ͬͯΔ͕ALBʹ͍ͨ͠ɻ ͔͠͠ɺCLB͸fluentd༻ʹ24224 (TCP)ΛListen͍ͯ͠ΔͷͰ ALBͷTCPରԠ଴ͪɻ

Slide 56

Slide 56 text

·ͱΊ

Slide 57

Slide 57 text

·ͱΊ Θ͔ͬͨ͜ͱ ɾDockerfile͸ಡΈ΍͘͢ॻ͍ͨ΄͏͕͍͍ɻ ɾόονͳΒECSԽ͸ͦΜͳʹϋϚΒͣεοͱͰ͖Δɻ ɾECSԽʹ൐͏Dockerize΍Autoscalingͷ෭࣍ޮՌ͕େ͖͍ɻ

Slide 58

Slide 58 text

͝੩ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠ ɾDockerfile͸ಡΈ΍͘͢ॻ͍ͨ΄͏͕͍͍ɻ ɾόονͳΒECSԽ͸ͦΜͳʹϋϚΒͣεοͱͰ͖Δɻ ɾECSԽʹ൐͏Dockerize΍Autoscalingͷ෭࣍ޮՌ͕େ͖͍ɻ 5)"/,:06 -FU`TUSZ&$4