SlideShare a Scribd company logo
CoreOSによるDockerコンテナのクラスタリング
CoreOSによるDockerコンテナのクラスタリング
CoreOSによるDockerコンテナのクラスタリング
CoreOSによるDockerコンテナのクラスタリング
CoreOSによるDockerコンテナのクラスタリング
CoreOSによるDockerコンテナのクラスタリング
CoreOSによるDockerコンテナのクラスタリング
CoreOSによるDockerコンテナのクラスタリング
CoreOSによるDockerコンテナのクラスタリング
CoreOSによるDockerコンテナのクラスタリング
CoreOSによるDockerコンテナのクラスタリング
CoreOSによるDockerコンテナのクラスタリング
CoreOSによるDockerコンテナのクラスタリング
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
CoreOSによるDockerコンテナのクラスタリング
CoreOSによるDockerコンテナのクラスタリング
CoreOSによるDockerコンテナのクラスタリング
CoreOSによるDockerコンテナのクラスタリング
CoreOSによるDockerコンテナのクラスタリング
CoreOSによるDockerコンテナのクラスタリング
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+ZTxC7weoIJLUaf 
Ogrm+h... 
write_files: 
- path: /etc/motd 
permissions: 0644 
owner: root 
content: | 
Good news, everyone!
CoreOSによるDockerコンテナのクラスタリング
#cloud-config 
coreos: 
update: 
reboot-strategy: best-effort 
etcd: 
# generate a new token for each unique cluster from https://discover 
y.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
write_files: 
- path: /tmp/busybox@.service 
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
# 必要に応じて 
gcloud config set project <project_id> 
gcloud config set compute/zone asia-east1-a 
gcloud 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.ya 
ml
# ログイン 
gcloud compute ssh core1 
# サービスの登録と起動 
fleetctl submit /tmp/busybox@.service 
fleetctl start busybox@{1,2}.service 
fleetctl list-units
# unitに割り当てのあるインスタンスを削除してみる 
gcloud compute instances delete core2 
gcloud compute ssh core1 
# フェイルオーバーが行われることを確認 
fleetctl list-units 
UNIT DSTATE STATE MACHINE ACTIVE 
busybox@.service inactive inactive - - 
busybox@1.service launched launched ffc81480.../10.xxx.xxx.237 active 
busybox@2.service launched launched 99f741a8.../10.xxx.xxx.150 active 
UNIT DSTATE STATE MACHINE ACTIVE 
busybox@.service inactive inactive - - 
busybox@1.service launched launched ffc81480.../10.xxx.xxx.237 active 
busybox@2.service launched launched 27c76d9a.../10.xxx.xxx.221 activa 
ting
CoreOSによるDockerコンテナのクラスタリング
CoreOSによるDockerコンテナのクラスタリング
CoreOSによるDockerコンテナのクラスタリング
CoreOSによるDockerコンテナのクラスタリング
CoreOSによるDockerコンテナのクラスタリング

More Related Content

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

  • 15. [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
  • 23. 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+ZTxC7weoIJLUaf Ogrm+h... write_files: - path: /etc/motd permissions: 0644 owner: root content: | Good news, everyone!
  • 25. #cloud-config coreos: update: reboot-strategy: best-effort etcd: # generate a new token for each unique cluster from https://discover y.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
  • 26. write_files: - path: /tmp/busybox@.service 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
  • 27. # 必要に応じて gcloud config set project <project_id> gcloud config set compute/zone asia-east1-a gcloud 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.ya ml
  • 28. # ログイン gcloud compute ssh core1 # サービスの登録と起動 fleetctl submit /tmp/busybox@.service fleetctl start busybox@{1,2}.service fleetctl list-units
  • 29. # unitに割り当てのあるインスタンスを削除してみる gcloud compute instances delete core2 gcloud compute ssh core1 # フェイルオーバーが行われることを確認 fleetctl list-units UNIT DSTATE STATE MACHINE ACTIVE busybox@.service inactive inactive - - busybox@1.service launched launched ffc81480.../10.xxx.xxx.237 active busybox@2.service launched launched 99f741a8.../10.xxx.xxx.150 active UNIT DSTATE STATE MACHINE ACTIVE busybox@.service inactive inactive - - busybox@1.service launched launched ffc81480.../10.xxx.xxx.237 active busybox@2.service launched launched 27c76d9a.../10.xxx.xxx.221 activa ting