Share
Embed
Container Cluster Strategy for PHP
PHPアプリケーションにおけるDockerコンテナ・クラスター戦略
https://saien.connpass.com/event/69375/
#再演 #phpcon2017
https://github.com/nishigori/phpcon2017-presentation
Takuya Nishigori
November 02, 2017
Transcript
64 slides
-
Container Cluster Strategy ~ How design for the PHP web
applica6on? ~ Docker Cluster Strategy - @_nishigori #phpcon2017 #࠶ԋ 1 -
Who are you? ɹTwi$er: @_nishigori • VOYAGE GROUP, Inc. SRE͑Μ͡ʹΌʔ
• ݩʑΞϓϦέʔγϣϯॻ͍ͯͯঃʑʹM/WԼʹ߱Γͯͬͨਓ • PHPͻͨ͢Βόʔδϣϯ্͛ͨΓɺOPcache࠷దԽਤͬͨΓ Docker Cluster Strategy - @_nishigori #phpcon2017 #࠶ԋ 2 -
Agenda • What Docker / Container ? • Orchestra4on •
Build & Deployment • Capacity Planning (& Monitoring) • History & Future Docker Cluster Strategy - @_nishigori #phpcon2017 #࠶ԋ 3 -
What Docker? Docker is the world's leading so3ware containeriza5on pla7orm.
-- h$ps:/ /www.docker.com/what-docker Docker Cluster Strategy - @_nishigori #phpcon2017 #࠶ԋ 5 -
What is the meaning of pla$orm? Kernel1 ͷػೳ༷ʑͳϥΠϒϥϦΛར༻ͯ͠ίϯςφΛಈ͔͍ͯ͠Δ containerd &
runC, rkt, Cgroups, Storage, Namespaces, Networking, Security pivot_root, chroot, etc ... ʹ ͻͱͭͷٕज़͚ͩͰͳ͍ɾͻͱͭͻͱͭସՄೳ 1 ͜ͷൃදͰLinux্ͷDockerʹ͍ͭͯͷΈݴٴ Docker Cluster Strategy - @_nishigori #phpcon2017 #࠶ԋ 7 -
What is the meaning of pla$orm? Code as: DockerfileͰContainer ImageΛ
ͲͷΑ͏ʹߏங͞ΕΔ͔දݱ # Dockerfile FROM nginx:alpine RUN rm -f /etc/nginx/conf.d/*.conf ADD nginx.conf /etc/nginx/nginx.conf RUN nginx -t EXPOSE 80 Docker Cluster Strategy - @_nishigori #phpcon2017 #࠶ԋ 8 -
What is the meaning of containerize? ίϯςφΛѻ͏ͨΊͷΠϯλʔϑΣʔε ͕ἧ͍ͬͯΔ $ docker
pull / push / build / run / image / container / ... Docker Cluster Strategy - @_nishigori #phpcon2017 #࠶ԋ 9 -
What Container? > Package so+ware into standardized units for development,
shipment and deployment A container image is a lightweight, stand- alone, executable package of a piece of so:ware that includes everything needed to run it: code, run>me, system tools, system libraries, se?ngs. -- h$ps:/ /www.docker.com/what- container Docker Cluster Strategy - @_nishigori #phpcon2017 #࠶ԋ 11 -
2 ... executable package of a piece of so3ware that
includes everything needed to run it: ... 2 h$ps:/ /www.docker.com/what-container ΑΓҾ༻ Docker Cluster Strategy - @_nishigori #phpcon2017 #࠶ԋ 14 -
needed to run it: run$me Docker Cluster Strategy - @_nishigori
#phpcon2017 #࠶ԋ 15 -
needed to run it: system tools, system libraries libxml /
libicu / openssl / libcurl / ... needed to run it: se#ngs php.ini / www.conf for php-fpm / ... ports? / memory limit / cpu unit / ... Docker Cluster Strategy - @_nishigori #phpcon2017 #࠶ԋ 16 -
needed to run it: code • Your code • e.g.
GitHub repository code • Dependencies code • e.g. from composer libraries Docker Cluster Strategy - @_nishigori #phpcon2017 #࠶ԋ 17 -
͋ͳͨͷPHPΞϓϦέʔγϣϯͷ needed run it: * ΛѲ͠ Container ImageΛ࡞͢Δ ᐌ͘: •
stand-alone ʢcontainer run,me͑͋͞Εେৎͦ͏ͩʣ • lightweightʢඞཁͳͷ͔͠ೖ͍ͬͯͳ͍ʣ • executable package ʢඞཁͳͷશͯἧͬͨͧ͌ʣ Docker Cluster Strategy - @_nishigori #phpcon2017 #࠶ԋ 18 -
[nits] Docker Build Pa4ern for PHP • Links container memory
... • memory_limit • opcache.memory_consumption • opcache.validate_timestamps=0 • ʢڪΒ͘ʣϦϦʔεৗʹίϯςφͷೖΕସ͑ͳͷͰɺphp fileͷߋ৽࣌ΛݟΔඞཁͳ͍ Docker Cluster Strategy - @_nishigori #phpcon2017 #࠶ԋ 21 -
What is Orchestra,on • εέδϡʔϦϯά • εέʔϧ • ϓϩϏδϣχϯά •
ࣗಈσϓϩΠ • Ϋϥελʔཧ • etc ... Docker Cluster Strategy - @_nishigori #phpcon2017 #࠶ԋ 23 -
Orchestra)on Public cloud provider: • Amazon EC2 Container Service (ECS)
• Azure Container Service (AKS) • Docker Enterprise Edi<on (Docker EE) • Google Container Service (GKE) Open Source: Docker Swarm / Kuberenes / Marathon / ... Docker Cluster Strategy - @_nishigori #phpcon2017 #࠶ԋ 24 -
3 Orchestra)onToolʹΑͬͯ༻ޠɾػೳ͕ҧ͏ͷͰɺ͜Ε͔Β AWS ECSΛྫʹ͠·͢ h"ps:/ /github.com/nishigori/phpcon2017-presenta9on 3 h$ps:/ /aws.amazon.com/ecs/details/ Docker
Cluster Strategy - @_nishigori #phpcon2017 #࠶ԋ 26 -
ECS Task • A group of one or more containers
• ײ֮ͱͯ͠ docker-composer up op2onsʹ͍͔ۙ • GKEͰ͍͏Podsͷ֓೦ʹ૬ Docker Cluster Strategy - @_nishigori #phpcon2017 #࠶ԋ 28 -
ECS Service • ECS TaskఆٛͰࢦఆ͞Εͨͷίϯς φΛஔ • + AutoScaling •
Service Load Balancing • ϗετ্ʹίϯςφͷϙʔτΛࣗಈ ׂΓͯ Docker Cluster Strategy - @_nishigori #phpcon2017 #࠶ԋ 29 -
ECS Cluster • ECS TaskΛஔ͢ΔίϯςφΠϯελ ϯεͷཧάϧʔϓ • EC2 AutoScaling Group
• EC2 Instance(s) • +AutoScaling Docker Cluster Strategy - @_nishigori #phpcon2017 #࠶ԋ 30 -
ECS Cluster Q. Which one should we choose Host OS?
A. ࣮ʹͨ͘͞Μ͋Δ… (AWS) Amazon ECS Op0mized AMI Container-Op0mized OS (Google) ContainerLinux (CoreOS) Barge OS etc ... Docker Cluster Strategy - @_nishigori #phpcon2017 #࠶ԋ 31 -
ECS Cluster Q. Which one should we choose Host OS?
• ͨ͘͞Μߟྀ͍ͯ͜͠͏ • Kernel version • Docker version • Launch 3me • etc ... Docker Cluster Strategy - @_nishigori #phpcon2017 #࠶ԋ 32 -
ECS Cluster - ContainerͱͷΓ߹͍ • Memory / CPU Reserva1on •
Memory / CPU Usage docker run --mem=1024m ... Docker Cluster Strategy - @_nishigori #phpcon2017 #࠶ԋ 33 -
Deployment - rolling update 1. ৽͍͠ίϯςφͷ্ཱͪ͛ 2. ELB͔ΒαʔϏεΠϯ 3. ݹ͍ίϯςφΛഁغ
Λ܁Γฦͯ͠શίϯςφΛೖΕସ͍͑ͯ͘ Docker Cluster Strategy - @_nishigori #phpcon2017 #࠶ԋ 36 -
Deployment - rolling update demo? Docker Cluster Strategy - @_nishigori
#phpcon2017 #࠶ԋ 37 -
Deployment for Ops (team) ~ rolling update to the ECS
Cluster ~ • Drain containers Docker Cluster Strategy - @_nishigori #phpcon2017 #࠶ԋ 38 -
Deployment - Canary -- h$ps:/ /mar,nfowler.com/bliki/CanaryRelease.html Docker Cluster Strategy -
@_nishigori #phpcon2017 #࠶ԋ 39 -
Deployment - Canary Q. Ͳ͔͜ΒΓ͚Δʁ 1. Load Balancer? 2. ECS
Cluster? 3. ECS Service? 4. Others? Docker Cluster Strategy - @_nishigori #phpcon2017 #࠶ԋ 40 -
Deployment - Canary Case of Docker EE: • Docker EE
Release Candidate • Customer Zero ਖ਼ʹ͖ʹ͑ΑελΠϧ Detail of dockercon EU 2017 - h7ps:/ /europe-2017.dockercon.com/ Docker Cluster Strategy - @_nishigori #phpcon2017 #࠶ԋ 41 -
Deployment - Container Image Management - ׂѪ - Docker Cluster
Strategy - @_nishigori #phpcon2017 #࠶ԋ 42 -
Deployment case of PHP OPcache / APCu ɺαʔϏεΠϯલʹWarmup͍ͨ͠ => ENTRYPOINT
Ͱఆٛͨ͠εΫϦϓτͰ͝ʹΐ͝ʹΐͯ͠Έ Α͏ # Dockerfile FROM xxx # .... ENTRYPOINT ["entrypint-app.sh"] CMD ["--env", "production"] Docker Cluster Strategy - @_nishigori #phpcon2017 #࠶ԋ 43 -
Logging ίϯςφʹʢجຊʣσʔλ͞ͳ͍ logྫ֎Ͱͳ͍ • Log as data • ΤʔδΣϯτʹΑΔPushܕ •
fluentd • cloudwatch log agent • ͍ΘΏΔதԝूݖܕʢCentralized loggingʣ Docker Cluster Strategy - @_nishigori #phpcon2017 #࠶ԋ 45 -
Logging on Dockerfile h"ps:/ /github.com/nginxinc/docker-nginx/blob/3ba04e3/mainline/ stretch/Dockerfile#L91-L93 # forward request and
error logs to docker log collector RUN ln -sf /dev/stdout /var/log/nginx/access.log \ && ln -sf /dev/stderr /var/log/nginx/error.log Docker Cluster Strategy - @_nishigori #phpcon2017 #࠶ԋ 46 -
Public Container Serviceपลٕज़େࣄ5 • (GCP) Load Balancer / BQ /
... • (AWS) S3 / SNS / SQS / ... • ... • SLA? • Using Reserved Instance? 5 k8s͍͍Αk8s Docker Cluster Strategy - @_nishigori #phpcon2017 #࠶ԋ 54 -
History 2013.03~ Docker 2014.06~ Docker Hub 2014.06~ Kubernetes (k8s, kube)
2014.11~ Amazon EC2 Container Service (ECS) 2014.11~ Google Container Engine (GKE) 2014.12~ CoreOS Rocket 2014.12~ Docker Machine / Swarm / Compose 2015.07~ Cloud Native Computing Foundation (CNCF) 2015.08~ VMware vSphere Integrated Containers 2015.09~ Microsoft Azure Container Services (ݱAKS) 2017.03~ Docker Enterprise Edition (Docker EE) 2017.04~ Moby Project 2017.07~ Microsoft Azure Container Instance (ACI) Docker Cluster Strategy - @_nishigori #phpcon2017 #࠶ԋ 56 -
History (Orchestra/on) 2013.03~ Docker 2014.06~ Docker Hub 2014.06~ Kubernetes (k8s,
kube) 2014.11~ Amazon EC2 Container Service (ECS) 2014.11~ Google Container Engine (GKE) 2014.12~ CoreOS Rocket 2014.12~ Docker Machine / Swarm / Compose 2015.07~ Cloud Native Computing Foundation (CNCF) 2015.08~ VMware vSphere Integrated Containers 2015.09~ Microsoft Azure Container Services (ݱAKS) 2017.03~ Docker Enterprise Edition (Docker EE) 2017.04~ Moby Project 2017.07~ Microsoft Azure Container Instance (ACI) Docker Cluster Strategy - @_nishigori #phpcon2017 #࠶ԋ 57 -
History (Orchestra/on) • Docker for Win/MacͰKubernetesڥߏஙՄೳʹ • 2017.11ݱࡏɺϕʔλ൛ͷਃ͠ࠐΈ͕Մೳ • h;ps:/
/beta.docker.com/ Docker Cluster Strategy - @_nishigori #phpcon2017 #࠶ԋ 58 -
History (Managed Service) 2013.03~ Docker 2014.06~ Docker Hub 2014.06~ Kubernetes
(k8s, kube) 2014.11~ Amazon EC2 Container Service (ECS) 2014.11~ Google Container Engine (GKE) 2014.12~ CoreOS Rocket 2014.12~ Docker Machine / Swarm / Compose 2015.07~ Cloud Native Computing Foundation (CNCF) 2015.08~ VMware vSphere Integrated Containers 2015.09~ Microsoft Azure Container Services (ݱAKS) 2017.03~ Docker Enterprise Edition (Docker EE) 2017.04~ Moby Project 2017.07~ Microsoft Azure Container Instance (ACI) Docker Cluster Strategy - @_nishigori #phpcon2017 #࠶ԋ 59 -
History (Managed Service) • 2014.05࣌ͰGoogle20ԯҎ্ͷίϯςφΛՔಇ͍ͯͨ͠ • h.ps:/ /speakerdeck.com/jbeda/containers-at-scale • AWS
Lambdaίϯςφٕज़Λར༻͍ͯ͠Δ • Public Cloudͱͯ͠Container Serviceొ͔ͯ͠Βطʹ3 Ҏ্ܦ͍ͬͯΔ Docker Cluster Strategy - @_nishigori #phpcon2017 #࠶ԋ 60 -
History (project / founda4on) 2013.03~ Docker 2014.06~ Docker Hub 2014.06~
Kubernetes (k8s, kube) 2014.11~ Amazon EC2 Container Service (ECS) 2014.11~ Google Container Engine (GKE) 2014.12~ CoreOS Rocket 2014.12~ Docker Machine / Swarm / Compose 2015.07~ Cloud Native Computing Foundation (CNCF) 2015.08~ VMware vSphere Integrated Containers 2015.09~ Microsoft Azure Container Services (ݱAKS) 2017.03~ Docker Enterprise Edition (Docker EE) 2017.04~ Moby Project 2017.07~ Microsoft Azure Container Instance (ACI) Docker Cluster Strategy - @_nishigori #phpcon2017 #࠶ԋ 61 -
History (project / founda4on) Cloud Na)ve Compu)ng Founda)on h2ps:/ /www.cncf.io/
• AWS2017.08~ joined • AWS LambdaͰΘΕ͍ͯΔίϯςφपΓͷϊϋ͕ϑ ΟʔυόοΫ͞ΕΔΜ͡Όͳ͍͔ͱݸਓతʹظ Docker Cluster Strategy - @_nishigori #phpcon2017 #࠶ԋ 62 -
btw: Cleanup aws for this presenta3on # https://github.com/nishigori/phpcon2017-presentation $ make
-C infrastructure destroy Docker Cluster Strategy - @_nishigori #phpcon2017 #࠶ԋ 64