Upgrade to Pro — share decks privately, control downloads, hide ads and more …

ECS を利用したデプロイ環境

ECS を利用したデプロイ環境

JAWS-UGおコンテナ支部 #5 発表資料
http://jawsug-container.connpass.com/event/32298/

hako: https://github.com/eagletmt/hako

Kohei Suzuki

June 27, 2016
Tweet

More Decks by Kohei Suzuki

Other Decks in Technology

Transcript

  1. Ξ΢τϥΠϯ • ΫοΫύουͱ Docker • Docker ΞϓϦͷσϓϩΠํ๏ v1 • ECS

    ҎલͷσϓϩΠํ๏ • Docker ΞϓϦͷσϓϩΠํ๏ v2 • ECS Λར༻ͨ͠σϓϩΠπʔϧ Hako ͷ։ൃ • Hako Λ࢖ͬͨσϓϩΠ؀ڥ
  2. ΫοΫύουͱ%PDLFS • 2015೥͔Βɺ৽نͷ Web ΞϓϦέʔγϣϯ͸جຊ తʹ Docker Λར༻ͨ͠؀ڥ (v1) Ͱಈ࡞

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

    5݄͔Βຊ൪Ͱ΋ར༻։࢝͠ɺݱ࣌఺Ͱ • ຊ൪Քಈ͍ͯ͠ΔαʔϏε͕ 2 ݸ • εςʔδϯά༻్ʹ 10 ݸ • ࣾ಺αʔϏεʹ 21 ݸ
  4. &$4Λ࢖͍࢝ΊΔલ • σϓϩΠํ๏Λߟ͑ɺϗετଆʹσϓϩΠεΫϦϓτ Λ༻ҙ͢Δ͜ͱʹͨ͠ • ඞཁͳ͜ͱ • Web ΞϓϦέʔγϣϯͷσϓϩΠΛແఀࢭͰߦ͏ •

    σϓϩΠ͸શ։ൃऀ͕ߦ͏͜ͱ͕Ͱ͖Δ • ։ൃऀʹ͸ൿಗ஋ (DB ύεϫʔυͳͲ) Λݟͤͳ͍ • ൿಗ஋͸؀ڥม਺ͱͯ͠౉͢
  5. σϓϩΠํ๏ W • 1ͭͷϗετʹ1ͭ·ͨ͸ෳ਺ͷ Docker ίϯςφ • ϗετଆʹ nginx Λ1ͭىಈ͠ɺHost

    ϔομͰίϯςφ ʹৼΓ෼͚ • σϓϩΠ࣌͸ɺίϯςφΛ৽نʹىಈ͠ɺnginx ͷઃఆ Λมߋͯ͠Ϧϩʔυ͠ɺݹ͍ίϯςφΛఀࢭ͢Δ • ৄ͘͠͸ http://techlife.cookpad.com/entry/ 2015/04/20/134758
  6. &$4Խ • ECS Λར༻͢Δ͜ͱͰɺσϓϩΠઌͷ੍ޚΛ೚ͤ Δ͜ͱ͕Ͱ͖Δ • EC2 λά͔Βͷղ์ • ECS

    Խʹ͋ͨͬͯൿಗ஋ͷѻ͍Λߟ͑Δ • task definition ͸Ӆͭͭ͠ɺผͷετϨʔδ͔Β ൿಗ஋Λ஫ೖ͢Δඞཁ͕͋Δ
  7. )BLP • Docker ίϯςφΛσϓϩΠ͢ΔͨΊͷπʔϧ • ࠓͷͱ͜Ζ ECS ͷΈʹରԠ • ΞϓϦέʔγϣϯͷఆٛΛ

    YAML Ͱهड़ • ൿಗ஋ΛؚΉ؀ڥม਺Λѻ͑Δ • σϓϩΠ࣌ʹ༷ʑͳॲཧΛࠩ͠ࠐΉ͜ͱ͕Ͱ͖Δ
  8. ઃܭϙϦγʔ • Ͱ͖Δ͚ͩ੩తͳఆٛʹ͢Δ • ఆٛ (ઃఆ) ͸ YAML Ͱɺίʔυ͸ Ruby

    Ͱ • ఆٛ͸ͦͷ··ͰɺRuby Ҏ֎Ͱ΋࣮૷Ͱ͖Δܗ • ϓϥΨϒϧʹ͢Δ • Docker ʹඞཁͳ΋ͷͷΈίΞʹؚΊΔ • ͦΕҎ֎ͷίʔυ͸ϓϥάΠϯͱͯࠩ͠͠ସ͑Մೳʹ ͢Δ
  9. ΞϓϦέʔγϣϯఆٛ 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
  10. σϓϩΠํ๏ W • Hako::Schedulers::Ecs • ECS ্ʹ serviceɺtask definitionɺELB Λ࡞੒

    • σϓϩΠ࣌ʹ͸ɺtask definition ͱ service Λߋ৽ • ͓ͦΒ͘ ECS ͷී௨ͷ࢖͍ํ
  11. σϓϩΠํ๏ W • YAML ͷఆٛͱ DescribeTaskDefinition ͷ݁ՌΛൺ ֱ • ඞཁʹԠͯ͡

    RegisterTaskDefinition Ͱߋ৽ • CreateService / UpdateService Ͱࢦ͍ͯ͠Δ task definition Λߋ৽ • CreateService ࣌ʹ͸ ELB ΋࡞੒͢Δ
  12. σϓϩΠํ๏ W ࣾ಺αʔϏε൛ • ͜ͷํ๏ͩͱ service ຖʹ ELB ͕ඞཁ •

    ࣾ಺޲͚ͷࡶαʔϏεͰ΋ຖճ ELB Λ࡞Δ…? • ڞ௨ͷ ELB Λ࢖͍ͭͭɺϦόʔεϓϩΩγͷઃఆΛ ͍͍͔Μ͡ʹมߋ͢ΔΑ͏ͳผͷϞʔυΛ࣮૷ • ࣾ಺ͷผͷج൫ʹґଘ͍ͯ͠ΔͷͰίʔυ͸ඇެ։ • Hako ͳΒσϓϩΠ෦෼͚ͩࠩ͠ସ͑Δ͜ͱ͕Մೳ
  13. )BLPΛ࢖ͬͨσϓϩΠ؀ڥ • σϓϩΠίϚϯυͷ࣮ߦʹ͸ Rundeck Λར༻ • app αʔόͰ࣮ߦ͢ΔίϚϯυ͕ແ͍ͷͰɺ Capistrano Λ࢖͏ඞཁ͕ͳ͍

    • Rundeck ্ͰδϣϒΛ࣮ߦ͢Δͱɺ • git clone git@repository:hako_apps.git • cd hako_apps && hako deploy nanika.yml
  14. όονॲཧ • hako oneshot Ͱ service Λ࢖ΘͣʹɺRunTask Ͱ୯ ൃͷλεΫΛ࣮ߦͰ͖Δ •

    ࣾ಺Ͱ͸ kuroko2 ͷλεΫͱ࣮ͯ͠ߦͰ͖ΔΑ͏ʹ ੔උ • kuroko2 ʹ͍ͭͯ͸ http://techlife.cookpad.com/ entry/2015/12/07/195732
  15. σϓϩΠ࣌ͷϑοΫ • Hako Ͱ͸ script ͱݺশ • σϓϩΠ࣌ʹ΍ͬͯΔ͜ͱ • Route53

    ͷࣗಈઃఆ • nginx ίϯςφͷΞΫηε੍ݶͷઃఆ • σϓϩΠ͢ΔΠϝʔδͷϦϏδϣϯΛ Jenkins ͷ݁Ռ ͔Βܾఆ • ౳ʑ
  16. ϩΪϯά • Docker ͷ log driver ΛࢦఆͰ͖Δ • fluentd log

    driver Λ࢖ͬͯɺϗετଆʹ fluentd Λཱͯ ͯɺ͔ͦ͜Β CloudWatch Logs ΁సૹ • service ໊΍ίϯςφ໊Λ log stream ͷ໊લʹؚΊΔ Α͏ʹ͍ͯ͠Δ • ద౰ͳΞϓϦͰαʔϏε͝ͱʹϩάΛӾཡͰ͖ΔΑ͏ʹ
  17. )BLPʹͳͬͯΑ͔ͬͨ఺ • ΠϯελϯεΛखಈͰ࡞੒͠ͳͯ͘Α͍ • AutoScaling Group ͷΩϟύγςΟΛ૿΍͚ͩ͢ • ΞϓϦέʔγϣϯͷఆٛΛɺ։ൃऀ͕ࣗ༝ʹӾཡɾߋ৽ Ͱ͖ΔΑ͏ʹͳͬͨ

    • ґཔͰ͸ͳ͘ pull-request ʹ • Route 53 ͷઃఆͳͲɺయܕతͳ࡞ۀΛࣗಈԽͰ͖ͨ • ݁Ռɺؾܰʹࣾ಺ΞϓϦ͕࡞ΒΕΔΑ͏ʹͳͬͨ
  18. ࠓޙͷల๬ • ECS Ҏ֎ͷαϙʔτ? • ͪΐ͏ͲઌिɺDocker 1.12 Ͱ orchestration ػೳ

    ͷڧԽ͕ൃද͞Εͨ • ͜ͷ service Λ Hako ͔Β੍ޚͰ͖ΔͱΑͦ͞͏ • https://blog.docker.com/2016/06/docker-1-12- built-in-orchestration/