KEMBAR78
Docker Swarm モード にゅうもん | PDF
I D C F ク ラ ウ ド × I n g r e s s L o a d B a l a n c i n g w / D o c k e r s w a r m m o d e
IDCF Cloud meetup vol.4
@zembutsu
Docker Swarm モード にゅうもん
みんな だいすき ドッカー です?
Dockerはアプリをどこでも簡単に動かす仕組み
swarmモードはクラスタ上のサービスを簡単管理
IDCFクラウドのロードバランサとも相性が良い
開発環境でDockerを使用
アプリ環境の管理のため
Dockerを使用
開発の機敏性を高めるため
Dockerを使用
アプリのポータビリティを
達成するためにDockerを使用
プロダクション用の
アプリでDocker使用
伝統的データベース
分散データベース
ビッグデータ
アプリ・サーバ
ウェブ・アプリ
ウェブ API
Dockerの役割
開発環境周辺で
Dockerの利用を計画
DevOps周辺で
Dockerの利用を計画
“Docker provides the software supply chain with agility, control and portability for app development.”
Dockerは開発のための機敏なソフトウェアのサプライチェーン、管理、ポータビリティを提供 [1]
The Evolution of the Modern Software Supply Chain - The Docker Survey, 2016
https://www.docker.com/survey-2016
Dockerイメージ
コンテナ実行時に必要なファイルシステム
tar アーカイブの中に Linux 用のファイル群が存在
イメージ・レイヤ(層)は読み込み専用
イメージはレイヤを共有
レイヤは親子関係を持つ
ディスク容量消費を回避し、移動しやすく
コンテナ起動時にイメージを使用
読み書き可能なレイヤを追加する
イメージ内のファイルを(isolate状態で)実行する
$ docker pull ubuntu
Using default tag: latest
latest: Pulling from library/ubuntu
203137e8afd5: Pull complet
2ff1bbbe9310: Pull complete
933ae2486129: Pull complete
a3ed95caeb02: Pull complete
Digest: sha256:1bea66e185d3464fec1abda32ffaf2a11de69833cfcf81bd2b9a5be147776814
Status: Downloaded newer image for ubuntu:latest/
Dockerコンテナの操作
OS ( Linux )
物理/仮想サーバ
Docker エンジン
( dockerd デーモン )
Linux kernel
コンテナ コンテナ コンテナ
リモート
API
docker
クライアント TCP あるいは
Unix ソケットドメイン
containerd
Runtime: runC (OCI規格準拠)
・docker コマンド
Linux, Mac OS X, Windows
・Kitematic (GUI)
Mac OS X, Windows
・Docker Compose
・Docker Swarm
コンテナのプロセス
httpd
PID 1
コンテナA コンテナB
ruby
PID 1
chris.rb
PID 2
/sbin/init
PID 1
httpd
PID 6
ruby
PID 7
chris.rb
PID 8
alice
PID 2
bob
PID 3
PPID 1 PPID 1
PPID 4
PPID 5 PPID 5
PPID 7
PPID 1
containerd
PID 5
dockerd
PID 4
コンテナのファイルシステム
コンテナAのファイルシステム
… …
コンテナBのファイルシステム
/etc
(/data/ubuntu/etc)
/bin
(/data/ubuntu/bin)
/etc
(/data/centos/etc)
/bin
(/data/centos/bin)
/ /
/
/etc
/data/ubuntu /data/centos
/bin /data
コンテナの実行
コンテナAのファイルシステム
… …
コンテナBのファイルシステム
/etc
(/data/ubuntu/etc)
/bin
(/data/ubuntu/bin)
/etc
(/data/centos/etc)
/bin
(/data/centos/bin)
/ /
httpd
PID 1
プロセスA プロセスB
ruby
PID 1
chris.rb
PID 2
コンテナA コンテナB
名前空間の isolate
・プロセス
・ファイルシステム
・ネットワーク
・ホスト名
・UID・GID
リソース制限
・CPU
・メモリ
・I/O
・ディスク・クォータ
Dockerコンテナの操作
OS ( Linux )
物理/仮想サーバ
Docker エンジン
( dockerd デーモン )
Linux kernel
コンテナ コンテナ コンテナ
リモート
API
docker
クライアント TCP あるいは
Unix ソケットドメイン
containerd
Runtime: runC (OCI規格準拠)
・docker コマンド
Linux, Mac OS X, Windows
・Kitematic (GUI)
Mac OS X, Windows
・Docker Compose
・Docker Swarm
$ docker run …
$ docker run …
$ docker run …
• 増減する環境
• 日々の運用
• 障害対応
internet
ゾーン:joule
仮想マシン 仮想マシン 仮想マシン
joule-network1
Port 80 Port 80 Port 80
仮想ルータ ( Firewall & Load Balancer )
・ DDoS 防御
・ 無償 (~ 3TB )
・ ヘルスチェック, 監視 [2]
・ SSD
・ ダイナミックスケール
・ オートスケールアップ
「それ、Docker使う意味あるの?」
…になりがちでは
開発サイド vs 運用サイド
internet
ゾーン:joule
仮想マシン 仮想マシン 仮想マシン
joule-network1
Port 80 Port 80 Port 80
仮想ルータ ( Firewall & Load Balancer )
ぼくは しんで しまった
なぞの こえ 「swarm モード を
つかうのじゃ!」
swarmモード
Docker標準搭載のクラスタとサービス管理機構
Docker Engine v1.12RC1 から Docker Swarm と機能統合 (SwarmKit) [3]
クラスタを “Swarm” とよび、マネージャがノード上のサービスを簡単に一括管理
管理はサービスとタスクの単位
アプリケーションの実行単位がサービス (service)であり、期待状態を定義
複製サービスとグローバル・サービスの2種類
タスクがコンテナのスケジューリング単位
マルチホスト対応のルーティング・メッシュ
期待状態を維持するために、タスクの自動増減の対応やヘルスチェック機能
外部サービスはIngressロード・バランシングで負荷分散し、内部も DNS を持つ [4]
internet
ゾーン:joule
仮想マシン 仮想マシン 仮想マシン
joule-network1
Port 80 Port 80 Port 80
仮想ルータ ( Firewall & Load Balancer )
・ DDoS 防御
・ 無償 (~ 3TB )
・ ヘルスチェック, 監視 [2]
・ SSD
・ ダイナミックスケール
・ オートスケールアップ
internet
ゾーン:joule
仮想マシン 仮想マシン 仮想マシン
joule-network1
Port 80 Port 80 Port 80
仮想ルータ ( Firewall & Load Balancer )
ingress
Overlay network
・ルーティング
・負荷分散
タスク タスク タスク
internet
ゾーン:joule
仮想マシン 仮想マシン 仮想マシン
joule-network1
仮想ルータ ( Firewall & Load Balancer )
ingress
Virtual Router
(IPVS)
タスク タスク タスク
Routing mesh
DEMO
swarm mode 基本コマンド
$ docker swarm init --listen-addr <host>:2377
$ docker swarm join <host>:<port>
$ docker service create ¥
--replicas N –p <公開port>:<内部> --name <名前> <イメージ>
$ docker service ls
$ docker service tasks <サービス名>
$ docker service update --replicas N <サービス名>
$ docker service update --image <イメージ> <サービス名>
$ docker service rm
クラスタ初期化
クラスタ参加
サービス作成
サービス一覧
タスク一覧
サービス更新
ローリング・アップデート
サービス削除
Docker image: zembutsu/docker-sample-nginx
FROM nginx:latest
COPY default.conf /etc/nginx/conf.d/
COPY index.html /usr/share/nginx/html/
<html>
<body>
<h1>Host: <!--#echo var="HOSTNAME" --></h1>
</body>
</html>
server {
listen 80;
server_name localhost;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
ssi on;
}
Dockerfile
index.html default.conf
Docker 1.12.0-rc2
CentOS Linux release 7.2.1511 (Core)
Linux manager-01 3.10.0-327.18.2.el7.x86_64 #1 SMP Thu May 12 11:03:55 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
internet
ゾーン:joule
manager-01 worker-01 worker-02
joule-network1
ingress
Overlay
network
nginx nginx nginx
210.140.82.136 (ロードバランサ設定)
worker-03
nginx
gateway: 10.15.0.1CIDR: 10.15.0.0/21
10.15.0.240 10.15.0.144 10.15.0.232 10.15.0.88
Port 80
Port 8080 Port 8080 Port 8080 Port 8080
Docker Engine 1.12 - Swarm mode demo 1/1
https://youtu.be/N3Xe9pGfBsc
internet
ゾーン:joule
manager-01 worker-01 worker-02
joule-network1
ingress
Overlay
network
nginx nginx nginx
210.140.82.136
worker-03
nginx
gateway: 10.15.0.1CIDR: 10.15.0.0/21
10.15.0.240 10.15.0.144 10.15.0.232 10.15.0.88
Port 80
Port 8080 Port 8080 Port 8080 Port 8080
Docker Engine 1.12 - Swarm mode demo 1/2
https://youtu.be/3HdMwH0hOVw
$ curl 210.140.82.136
<html>
<body>
<h1>Host: 84b779f301c8</h1>
</body>
</html>
zembutsu@zembutsu-PC ~
$ curl 210.140.82.136
<html>
<body>
<h1>Host: 1683ce28dd42</h1>
</body>
</html>
zembutsu@zembutsu-PC ~
$ curl 210.140.82.136
<html>
<body>
<h1>Host: e78086a4e53a</h1>
</body>
</html>
※Docker 1.12-RC2現在の情報です。
※リリース候補版のため、
将来的に仕様が変わる可能性や、
バグを含む可能性があります。
Dockerはアプリをどこでも簡単に動かす仕組み
swarmモードはクラスタ上のサービスを簡単管理
IDCFクラウドのロードバランサとも相性が良い
なにか きになる ところ ありますか?
ありがとうございました
参考
[1] The Evolution of the Modern Software Supply Chain - The Docker Survey, 2016
https://www.docker.com/survey-2016/
[2] 実話!実はIDCFクラウドって◯◯なんです
http://www.slideshare.net/IDCFrontier/idcf
[3] Swarm mode key concepts
https://docs.docker.com/engine/swarm/key-concepts/
[4] Docker for Ops: Docker Networking Deep Dive, Considerations and Troubleshooting
http://www.slideshare.net/Docker/docker-for-ops-docker-networking-deep-dive-considerations-and-
troubleshooting-by-madhu-venugopal-and-jana-radhakrishnan
補足資料:
Swarm mode overview
https://docs.docker.com/engine/swarm/
Docker 1.12: swarm モードと Ingress Load Balancing 概要 · Pocketstudio Technology Log
https://pocketstudio.net/2016/06/23/docker-1-12-swarm-mode-and-ingress-load-balancing/

Docker Swarm モード にゅうもん