CoreOSによるDockerコンテナのクラスタリング

34

description

2014年09月06日(土)に行われた第4回 コンテナ型仮想化の情報交換会@東京の発表資料。

Transcript of CoreOSによるDockerコンテナのクラスタリング

Page 1: CoreOSによるDockerコンテナのクラスタリング
Page 2: CoreOSによるDockerコンテナのクラスタリング
Page 3: CoreOSによるDockerコンテナのクラスタリング
Page 4: CoreOSによるDockerコンテナのクラスタリング
Page 5: CoreOSによるDockerコンテナのクラスタリング
Page 6: CoreOSによるDockerコンテナのクラスタリング
Page 7: CoreOSによるDockerコンテナのクラスタリング
Page 8: CoreOSによるDockerコンテナのクラスタリング
Page 9: CoreOSによるDockerコンテナのクラスタリング
Page 10: CoreOSによるDockerコンテナのクラスタリング
Page 11: CoreOSによるDockerコンテナのクラスタリング
Page 12: CoreOSによるDockerコンテナのクラスタリング
Page 13: CoreOSによるDockerコンテナのクラスタリング
Page 14: CoreOSによるDockerコンテナのクラスタリング
Page 15: CoreOSによるDockerコンテナのクラスタリング

[Unit]

Description=busybox

Requires=docker.service

After=docker.service

[Service]

TimeoutStartSec=0

ExecStartPre=-/usr/bin/docker kill busybox

ExecStartPre=-/usr/bin/docker rm busybox

ExecStartPre=/usr/bin/docker pull busybox

ExecStart=/usr/bin/docker run --name busybox busybox /bin/sh -c "while

true; do echo Hello World; sleep 1; done"

ExecStop=/usr/bin/docker stop busybox

[X-Fleet]

X-Conflicts=busybox@*.service

Page 16: CoreOSによるDockerコンテナのクラスタリング
Page 17: CoreOSによるDockerコンテナのクラスタリング
Page 18: CoreOSによるDockerコンテナのクラスタリング
Page 19: CoreOSによるDockerコンテナのクラスタリング
Page 20: CoreOSによるDockerコンテナのクラスタリング
Page 21: CoreOSによるDockerコンテナのクラスタリング
Page 22: CoreOSによるDockerコンテナのクラスタリング
Page 23: CoreOSによるDockerコンテナのクラスタリング

coreos: etcd: discovery: https://discovery.etcd.io/<token> addr: $private_ipv4:4001 peer-addr: $private_ipv4:7001 units: - name: etcd.service command: start - name: fleet.service command: start

ssh_authorized_keys: - ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC0g+ZTxC7weoIJLUafOgrm+h...

write_files: - path: /etc/motd permissions: 0644 owner: root content: | Good news, everyone!

Page 24: CoreOSによるDockerコンテナのクラスタリング
Page 25: CoreOSによるDockerコンテナのクラスタリング

#cloud-config

coreos: update: reboot-strategy: best-effort etcd: # generate a new token for each unique cluster from https://discovery.etcd.io/new discovery: https://discovery.etcd.io/<token> addr: $private_ipv4:4001 peer-addr: $private_ipv4:7001 units: - name: etcd.service command: start - name: fleet.service command: start

Page 26: CoreOSによるDockerコンテナのクラスタリング

write_files:

- path: /tmp/[email protected]

content: |

[Unit]

Description=busybox

Requires=docker.service

After=docker.service

[Service]

TimeoutStartSec=0

ExecStartPre=-/usr/bin/docker kill busybox-%i

ExecStartPre=-/usr/bin/docker rm busybox-%i

ExecStartPre=/usr/bin/docker pull busybox

ExecStart=/usr/bin/docker run --name busybox-%i busybox /bin/sh -

c "while true; do echo Hello World; sleep 1; done"

ExecStop=/usr/bin/docker stop busybox-%i

[X-Fleet]

X-Conflicts=busybox@*.service

Page 27: CoreOSによるDockerコンテナのクラスタリング

# 必要に応じてgcloud config set project <project_id>gcloud config set compute/zone asia-east1-agcloud config set compute/region asia-east1

# 3つのインスタンスを起動gcloud compute instances create core1 core2 core3 --image coreos \ --machine-type f1-micro --metadata-from-file user-data=cloud-config.yaml

Page 28: CoreOSによるDockerコンテナのクラスタリング

# ログインgcloud compute ssh core1

# サービスの登録と起動fleetctl submit /tmp/[email protected] start busybox@{1,2}.servicefleetctl list-units

Page 29: CoreOSによるDockerコンテナのクラスタリング

# unitに割り当てのあるインスタンスを削除してみる

gcloud compute instances delete core2

gcloud compute ssh core1

# フェイルオーバーが行われることを確認

fleetctl list-units

UNIT DSTATE STATE MACHINE ACTIVE

[email protected] inactive inactive - -

[email protected] launched launched ffc81480.../10.xxx.xxx.237 active

[email protected] launched launched 99f741a8.../10.xxx.xxx.150 active

UNIT DSTATE STATE MACHINE ACTIVE

[email protected] inactive inactive - -

[email protected] launched launched ffc81480.../10.xxx.xxx.237 active

[email protected] launched launched 27c76d9a.../10.xxx.xxx.221 activa

ting

Page 30: CoreOSによるDockerコンテナのクラスタリング
Page 31: CoreOSによるDockerコンテナのクラスタリング
Page 32: CoreOSによるDockerコンテナのクラスタリング
Page 33: CoreOSによるDockerコンテナのクラスタリング
Page 34: CoreOSによるDockerコンテナのクラスタリング