theme: Plain Jane, 1 build-lists: true footer: Docker Cluster Strategy - @_nishigori #phpcon2017 #再演 slidenumbers: true
- VOYAGE GROUP, Inc. SREえんじにゃー
- 元々アプリケーション書いてて徐々にM/W等下に降りてった人
- PHPはひたすらバージョン上げたり、OPcache最適化図ったり
- What Docker / Container ?
- Orchestration
- Build & Deployment
- Capacity Planning (& Monitoring)
- History & Future
Docker is the world's leading software containerization platform.
-- https://www.docker.com/what-docker
[fit] Kernel1 の機能や様々なライブラリを利用してコンテナを動かしている
containerd & runC, rkt, Cgroups, Storage, Namespaces, Networking, Security pivot_root, chroot, etc ...
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 pull / push / build / run / image / container / ...
A container image is a lightweight, stand-alone, executable package of a piece of software that includes everything needed to run it: code, runtime, system tools, system libraries, settings.
-- https://www.docker.com/what-container
2 ... executable package of a piece of software that includes everything needed to run it: ...
libxml / libicu / openssl / libcurl / ...
php.ini / www.conf for php-fpm / ...
ports? / memory limit / cpu unit / ...
- Your code
- e.g. GitHub repository code
- Dependencies code
- e.g. from composer libraries
あなたのPHPアプリケーションの needed run it: *
を把握しContainer Imageを作成する
曰く:
- stand-alone (container runtimeさえあれば大丈夫そうだ)
- lightweight(必要なものしか入っていない)
- executable package (必要なものは全て揃ったぞぃ)
- Links container memory ...
memory_limit
opcache.memory_consumption
opcache.validate_timestamps=0
- (恐らく)リリースは常にコンテナの入れ替えなので、php fileの更新日時を見る必要はない
- スケジューリング
- スケール
- プロビジョニング
- 自動デプロイ
- クラスター管理
- etc ...
Public cloud provider:
- Amazon EC2 Container Service (ECS)
- Azure Container Service (AKS)
- Docker Enterprise Edition (Docker EE)
- Google Container Service (GKE)
Open Source: Docker Swarm / Kuberenes / Marathon / ...
OrchestrationはToolによって用語・機能が違うので、これからはAWS ECSを例に話します
- A group of one or more containers
- 感覚としては
docker-composer up
optionsに近いかも - GKEでいうPodsの概念に相当
- ECS Task定義で指定された数のコンテナを配置
-
- AutoScaling
- Service Load Balancing
- ホスト上にコンテナのポートを自動割り当て
- ECS Taskを配置するコンテナインスタンスの論理グループ
- EC2 AutoScaling Group
- EC2 Instance(s)
- +AutoScaling
Q. Which one should we choose Host OS? A. 実にたくさんある…
(AWS) Amazon ECS Optimized AMI Container-Optimized OS (Google) ContainerLinux (CoreOS) Barge OS etc ...
Q. Which one should we choose Host OS?
- たくさん考慮していこう
- Kernel version
- Docker version
- Launch time
- etc ...
- Memory / CPU Reservation
- Memory / CPU Usage
docker run --mem=1024m ...
- 新しいコンテナの立ち上げ
- ELBからサービスイン
- 古いコンテナを破棄
を繰り返して全コンテナを入れ替えていく
- Drain containers
-- https://martinfowler.com/bliki/CanaryRelease.html
Q. どこから切り分ける?
- Load Balancer?
- ECS Cluster?
- ECS Service?
- Others?
Case of Docker EE:
- Docker EE Release Candidate
- Customer Zero
正に好きに使えよスタイル
[fit] Detail of dockercon EU 2017 - https://europe-2017.dockercon.com/
=> ENTRYPOINT で定義したスクリプト内でごにょごにょしてみよう
# Dockerfile
FROM xxx
# ....
ENTRYPOINT ["entrypint-app.sh"]
CMD ["--env", "production"]
コンテナに(基本)データは残さない logも例外ではない
- Log as data
- エージェントによるPush型
- fluentd
- cloudwatch log agent
- いわゆる中央集権型(Centralized logging)
https://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
ガッ4
ガッ5
ガッ6
Public Container Serviceは周辺技術も大事5
- (GCP) Load Balancer / BQ / ...
- (AWS) S3 / SNS / SQS / ...
- ...
- SLA?
- Using Reserved Instance?
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)
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 for Win/MacでKubernetes環境も構築可能に
- 2017.11現在、ベータ版の申し込みが可能
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)
- 2014.05時点でGoogleは20億以上のコンテナを稼働していた
- AWS Lambdaもコンテナ技術を利用している
- Public CloudとしてもContainer Serviceは登場してから既に3年以上経っている
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)
Cloud Native Computing Foundation https://www.cncf.io/
- AWSは2017.08~ joined
- AWS Lambda等で使われているコンテナ周りのノウハウがフィードバックされるんじゃないかと個人的に期待
# https://github.com/nishigori/phpcon2017-presentation
$ make -C infrastructure destroy