Share
Embed
Transcript
28 slides
-
Copyright © 2009-2015 eureka, inc. All rights reserved. CONFIDENTIAL pairsͷϓϩϏδϣχϯάཁ݅ͱ
Infrastructure as Code࣮ྫ 5BLVZB0OEB/ eureka, inc. # Eureka x MTI Tech Beer -
CONFIDENTIAL Copyright © 2009-2015 eureka, inc. All rights reserved. ࣗݾհ
• ໊લɿԸా • dגࣜձࣾσΟʔɾΤψɾΤʔ • dגࣜձࣾΤϨΧ • ͓͠͝ͱ • ΤϨΧͷΠϯϑϥपΓશൠΛ୲͍ͯ͠·͢ • ωοτϫʔΫ%#ࢹੳج൫ηΩϡϦςΟFUD • ϒϩάɿIUUQTEFWFMPQFSTFVSFKQNFNCFST UBLVZB@POEB -
CONFIDENTIAL Copyright © 2009-2015 eureka, inc. All rights reserved. ࠓͷτϐοΫ
• QBJSTͷαʔϏεಛੑͱٻΊΒΕΔϓϩϏδϣχϯάཁ݅ • *OGSBTUSVDUVSFBTDPEF࣮ફʹΑΔ՝ղܾ • ࣮ྫհdαʔόߏஙαʔϏεΠϯ·ͰͷྲྀΕ -
CONFIDENTIAL Copyright © 2009-2015 eureka, inc. All rights reserved. pairsͷαʔϏεಛੑ
• "84Λϑϧ׆༻ • &$୯Ґ࣌ؒ I ຖʹ՝ۚൃੜ • ΦϯϓϨͱൺֱ͢Δͱαʔό͋ͨΓίετߴ • ߴසσϓϩΠՕॴͱසσϓϩΠՕॴ • ߴසɿΞϓϦέʔγϣϯຊମ • සɿը૾৴αʔόɺEFRVFVFXPSLFS • Θ͔Γ͍͢ϐʔΫλΠϜ • d࣌ ேͷϓογϡ௨ • ϝσΟΞ࿐ग़ʹΑΔεύΠΫ΄ͱΜͲͳ͍ -
CONFIDENTIAL Copyright © 2009-2015 eureka, inc. All rights reserved. ٻΊΒΕΔϓϩϏδϣχϯάཁ݅
• ̍ɿίετYߴՄ༻ੑ • ϐʔΫλΠϜʹ߹Θͤͨ͠ͳ͔ͳϦιʔε૿ݮ • ɿߴ͍ηΩϡϦςΟཁٻ • αʔϏεಛੑ্ɺηΩϡϦςΟϗʔϧக໋త • ̏ɿඇଐਓతͳϫʔΫϑϩʔ • Ϧιʔε࡞ՃআΛ୭Ͱग़དྷΔ࡞ۀʹ • φϦοδͷଐਓԽσϦόϦεϐʔυΛམͱ͢ • ʮ͋ʙɺ͜Εʓʓ͞Μ͡Όͳ͍ͱ͔Βͳ͍͢Θʙʯ -
CONFIDENTIAL Copyright © 2009-2015 eureka, inc. All rights reserved. Infrastructure
as Code࣮ફʹΑΔ՝ղܾ • ̍ɿίετYߴՄ༻ੑ • ଈೖՄೳͳαʔόΛ͙͢࡞ΕΔ • ɿߴ͍ηΩϡϦςΟཁٻ • ωοτϫʔΫ 71$ ͱݖݶཧ *". ͷҰݩཧ • ̏ɿඇଐਓతͳϫʔΫϑϩʔ • ϓϩάϥϚϒϧඇΠϯϑϥͷਓؒͰ৮ΕΔ • ίʔυΛݟΕ࡞എܠཤྺ͕Θ͔Δ • (JUIVC'MPXΩϟύγςΟϓϥϯχϯά -
CONFIDENTIAL Copyright © 2009-2015 eureka, inc. All rights reserved. ϦιʔεೖϙϦγʔ
• ߴσϓϩΠՕॴ • ࣌ؒଳεέʔϦϯάʹΑΔϦιʔε૿ݮ • σϓϩΠՕॴ • ϝτϦΫεϕʔεͷ"VUP4DBMJOH -
CONFIDENTIAL Copyright © 2009-2015 eureka, inc. All rights reserved. ϦιʔεೖϙϦγʔ
• ߴσϓϩΠՕॴ • ίϚϯυҰൃͰ࠷৽ͷαʔό࡞Ͱ͖Ε0,ͱׂΓ • DSPOͱ͔ͰࠐΊ࣌ؒଳεέʔϦϯάͷग़དྷ্͕Γ • σϓϩΠՕॴ • ΰʔϧσϯΠϝʔδΛอ࣋ • ࠷৽ͷ"QQ͕ࡌͬͯΔ".*Λݩʹ"VUP4DBMJOH -
Ansible Serverspec Terraform Create All Resources on AWS Provisioning
And Deployment Provisioning Process (Manual / Scheduled-Scaling) Implement Test -
Create server with tags Provisioning and deploy current app
version Implement test recipe on each role cd /path/pairs/prod/jp terraform apply cd /path/to/test rake pairs:prod/jp/web cd /path/to/ansible_dir ansible-playbook -i hosts/pairs/prod/jp playbook playbook/web.yml exists servers Attach to ELB Activator Ops ᶃ ᶄ ᶅ ᶆ • Scheduled Activation • Semi Automatic Activation -
cd /path/pairs/prod/jp terraform apply cd /path/to/test rake pairs:prod/jp/web Create server
with tags Implement test recipe on each role Provisioning process • Server creation • Via terraform & add tags • Provisioning & deploy • Using dynamic inventory • Implement test recipe • Using Ruby AWS SDK • Attach to ELB • Name:pairs-jp-web-xx • env:prod • regin:jp • role:web exists servers Provisioning and deploy current app version cd /path/to/ansible_dir ansible-playbook -i hosts/pairs/prod/jp playbook playbook/web.yml ᶃ ᶄ ᶅ -
• Name:pairs-jp-web-xx • env:prod • regin:jp • role:web Create server
with tags Provisioning deploy Test middleware and app status cd /path/pairs/prod/jp terraform apply cd /path/to/test rake pairs:prod/jp/web cd /path/pairs/prod/jp ansible-playbook -i hosts/pairs/prod/jp playbook playbook/web.yml Procedure for Provisioning • Server creation • via terraform & add tags • Provisioning & deploy • Using dynamic inventory • Implement test recipe • Using Ruby AWS SDK # Example ) Additional App Server Recipe resource "aws_instance" "web_xx" { ami = "ami-xxxxxxx" instance_type = "${var.ec2.app.instance_type}" availability_zone = "${var.vpc.region_1a}" security_groups = ["${aws_security_group.app.id}"] subnet_id = "${aws_subnet.app_1a.id}" ebs_optimized = "${var.ec2.app.ebs_optimized}" iam_instance_profile = "${var.ec2.app.iam_instance_profile}" count = 1 tags { Name = “pairs-jp-web-xx” # Unique name for each server role = “pairs-jp-web” # Group for provisioning region = "jp" env = "prod" } } -
cd /path/pairs/prod/jp terraform apply cd /path/to/test rake pairs:prod/jp/web Create server
with tags Provisioning process • Server creation • Via terraform & add tags • Provisioning & deploy • Using dynamic inventory • Implement test recipe • Using Ruby AWS SDK • Attach to ELB Belong to same env/region/role exists servers Provisioning and deploy current app version cd /path/to/ansible_dir ansible-playbook -i hosts/pairs/prod/jp playbook playbook/web.yml ᶃ ᶄ ᶅ • Name:pairs-jp-web-xx • env:prod • regin:jp • role:web Implement test recipe on each role -
cd /path/pairs/prod/jp terraform apply cd /path/to/test rake pairs:prod/jp/web Create server
with tags Provisioning process • Server creation • Via terraform & add tags • Provisioning & deploy • Using dynamic inventory • Implement test recipe • Using Ruby AWS SDK • Attach to ELB • Name:pairs-jp-web-xx • env:prod • regin:jp • role:web exists servers Provisioning and deploy current app version cd /path/to/ansible_dir ansible-playbook -i hosts/pairs/prod/jp playbook playbook/web.yml ᶃ ᶄ ᶅ Dynamically fetched via ec2.py Implement test recipe on each role -
cd /path/pairs/prod/jp terraform apply cd /path/to/test rake pairs:prod/jp/web Create server
with tags Provisioning process • Server creation • Via terraform & add tags • Provisioning & deploy • Using dynamic inventory • Implement test recipe • Using Ruby AWS SDK • Attach to ELB exists servers Provisioning and deploy current app version cd /path/to/ansible_dir ansible-playbook -i hosts/pairs/prod/jp playbook playbook/web.yml • Name:pairs-jp-web-xx • env:prod • regin:jp • role:web ᶃ ᶄ ᶅ Dynamically fetched via ruby aws sdk Implement test recipe on each role -
cd /path/pairs/prod/jp terraform apply cd /path/to/test rake pairs:prod/jp/web Create server
with tags Implement test recipe on each role Procedure for Provisioning • Server creation • Via terraform & add tags • Provisioning & deploy • Using dynamic inventory • Implement test recipe • Using Ruby AWS SDK • Name:pairs-jp-web-xx • env:prod • regin:jp • role:web exists servers Provisioning and deploy current app version cd /path/to/ansible_dir ansible-playbook -i hosts/pairs/prod/jp playbook playbook/web.yml # Example ) inventory-1 [tag_role_pairs-jp-web] [tag_role_pairs-jp-admin] [tag_role_pairs-jp-batch] [tag_role_pairs-jp-db-master] [tag_role_pairs-jp-db-slave] [common:children] tag_role_pairs-jp-web tag_role_pairs-jp-mobile tag_role_pairs-jp-admin tag_role_pairs-jp-batch tag_role_pairs-jp-db-master tag_role_pairs-jp-db-slave [web:children] tag_role_pairs-jp-web # Example ) inventory-2 [admin:children] tag_role_pairs-jp-admin [batch:children] tag_role_pairs-jp-batch [db-master:children] tag_role_pairs-jp-db-master [db-slave:children] tag_role_pairs-jp-db-slave [db-all:children] tag_role_pairs-jp-db-master tag_role_pairs-jp-db-slave -
cd /path/pairs/prod/jp terraform apply cd /path/to/test rake pairs:prod/jp/web Create server
with tags Implement test recipe on each role Procedure for Provisioning • Server creation • Via terraform & add tags • Provisioning & deploy • Using dynamic inventory • Implement test recipe • Using Ruby AWS SDK • Name:pairs-jp-web-xx • env:prod • regin:jp • role:web exists servers Provisioning and deploy current app version cd /path/to/ansible_dir ansible-playbook -i hosts/pairs/prod/jp playbook playbook/web.yml # Example ) playbook for web server # Dynamic inventory Script : hosts/pairs/prod/jp/ec2.py # Var file : hosts/pairs/prod/jp/group_vars/all.yml --- # For web-server # Usage # ansible-playbook -i hosts/pairs/prod/jp playbook/web.yml - hosts: web gather_facts: yes vars_files: - "{{ inventory_dir }}/group_vars/secret.yml" roles: - { role: common, tags: common } - { role: mysql_client, tags: mysql_client } - { role: nginx, tags: nginx } - { role: mackerel, tags: mackerel } - { role: circus, tags: circus } - { role: td-agent, tags: td-agent } - { role: haproxy, tags: haproxy } -
cd /path/pairs/prod/jp terraform apply cd /path/to/test rake pairs:prod/jp/web cd /path/pairs/prod/jp
ansible-playbook -i hosts/pairs/prod/jp playbook playbook/web.yml Create server with tags Implement test recipe on each role Procedure for Provisioning • Server creation • Via terraform & add tags • Provisioning & deploy • Using dynamic inventory • Implement test recipe • Using Ruby AWS SDK • Name:pairs-jp-web-xx • env:prod • regin:jp • role:web exists servers Provisioning and deploy current app version # Example ) Rakefile (Fetch active instance list) require 'rake' require 'rspec/core/rake_task' require 'aws-sdk-v1' if ENV['AWS_ACCESS_KEY_ID'] && ENV['AWS_SECRET_ACCESS_KEY'] AWS.config( { access_key_id: ENV['AWS_ACCESS_KEY_ID'], secret_access_key: ENV['AWS_SECRET_ACCESS_KEY'], region: 'ap-northeast-1' } ) ec2_hosts = AWS.ec2.instances.select { |i| i.status == :running } end -
cd /path/pairs/prod/jp terraform apply cd /path/to/test rake pairs:prod/jp/web cd /path/pairs/prod/jp
ansible-playbook -i hosts/pairs/prod/jp playbook playbook/web.yml Create server with tags Implement test recipe on each role Procedure for Provisioning • Server creation • Via terraform & add tags • Provisioning & deploy • Using dynamic inventory • Implement test recipe • Using Ruby AWS SDK • Name:pairs-jp-web-xx • env:prod • regin:jp • role:web exists servers Provisioning and deploy current app version # Example ) Rakefile (Define test tasks # Pseudo code) # test recipe : spec/prod/jp/web_spec.rb / spec/common/comon.rb if ec2_hosts ec2_hosts.each do |host| task_name = "#{host_env}:#{host_region}:#{host_group}" spec_pattern = "spec/#{host_env}/#{host_region}/#{host_group} _spec.rb" # define tasks for each roles desc "Run serverspec tests to ec2 #{host_name} (PATH=#{spec_pattern},IP=#{host_ip})" RSpec::Core::RakeTask.new(host_name.to_sym) do |t| ENV['TARGET_HOST'] = host_ip ENV['TARGET_HOST_NAME'] = host_name t.pattern = "#{spec_pattern},spec/common/*_spec.rb" end end end -
cd /path/pairs/prod/jp terraform apply cd /path/to/test rake pairs:prod/jp/web Create server
with tags Provisioning process • Server creation • Via terraform & add tags • Provisioning & deploy • Using dynamic inventory • Implement test recipe • Using Ruby AWS SDK • Attach to ELB • Name:pairs-jp-web-xx • env:prod • regin:jp • role:web exists servers Attach to ELB cd /path/to/ansible_dir ansible-playbook -i hosts/pairs/prod/jp playbook playbook/web.yml Provisioning and deploy current app version ᶃ ᶄ ᶅ ᶆ Implement test recipe on each role -
Create server with tags Provisioning and deploy current app
version Implement test recipe on each role cd /path/pairs/prod/jp terraform apply cd /path/to/test rake pairs:prod/jp/web cd /path/to/ansible_dir ansible-playbook -i hosts/pairs/prod/jp playbook playbook/web.yml exists servers Attach to ELB Activator Ops ᶃ ᶄ ᶅ ᶆ • Scheduled Activation • Semi Automatic Activation -
Destruct Instances cd /path/pairs/prod/jp terraform apply cd /path/to/test rake pairs:prod/jp/web
cd /path/to/ansible_dir ansible-playbook -i hosts/pairs/prod/jp playbook playbook/web.yml exists servers Detach From ELB Activator Ops ᶄ ᶃ • Scheduled Destruction • Semi Automatic Destruction -
Scale Out Scale In Alert Monitored Via Cloudwatch Launch
New Instance by Scaling Policy Provisioning Process (Auto Scaling) Terminate Instance to be Desired -
ᶃ ᶅ S-In to Production Alert Firing Initialize Auto
Scaling Launch New Instances ᶄ -
ᶃ ᶅ S-In to Production Alert Firing Initialize Auto
Scaling Launch New Instances ᶄ Notify to Slack -
CONFIDENTIAL Copyright © 2009-2015 eureka, inc. All rights reserved. ·ͱΊ
• QBJSTΫϥυωΠςΟϒͳΠϯϑϥߏ • ͠ͳ͔ͳϦιʔε૿ݮηΩϡϦςΟཁ݅ଐਓੑͷഉআ • *OGSBTUSVDUVSFBT$PEFͷશ໘ಋೖͰղܾ ͨ͠ -
CONFIDENTIAL Copyright © 2009-2015 eureka, inc. All rights reserved. ͓·͚
• ࠓͷɺ࠷ۙॻ͍ͨϒϩάʹৄࡉॻ͍ͯͨΓ͠·͢ • ڵຯ͋Δ͔ͨΑ͚Εʂ • IUUQTEFWFMPQFSTFVSFKQUFDIUFSSBGPSN@VQEBUF