05 June 2016

Latihan Membuat Cluster Docker dengan Docker Swarm di openSUSE Leap 42

Referensi:


Topologi:

Langkah-langkah:
1. Di semua node pasang docker engine. Sesuaikan alamat IP untuk opsi --cluster-advertise dengan alamat IP masing-masing node.
# zypper in -y docker
# vim /etc/sysconfig/docker
..........
DOCKER_OPTS="-H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock --cluster-store=consul://10.10.10.10:8500 --cluster-advertise=10.10.10.XXX:2375"

# systemctl start docker.service
# systemctl enable docker.service
# systemctl status docker.service

2. Di node0 jalankan consul sebagai discovery backend.
# docker run -d --restart=always --name=consul -h consul -p 8500:8500 progrium/consul -server -bootstrap

3. Di node0 jalankan swarm manager (primary manager).
# docker run -d --restart=always --name swarm-manager -h swarm-manager -p 4000:4000 swarm manage -H :4000 --replication --advertise 10.10.10.10:4000 consul://10.10.10.10:8500

4.  Di node1 dan node2 jalankan swarm untuk bergabung ke cluster. Sesuaikan nama node dan alamat IP untuk opsi --name, -h, --advertise dengan nama dan alamat IP masing-masing node.
# docker run -d --restart=always --name=swarm-nodeX -h swarm-nodeX swarm join --advertise=10.10.10.XXX:2375 consul://10.10.10.10:8500

5. Di node0 verifikasi cluster.
# docker -H :4000 info
Containers: 2
Images: 2
Server Version: swarm/1.2.3
Role: primary
Strategy: spread
Filters: health, port, containerslots, dependency, affinity, constraint
Nodes: 2
 node1: 10.10.10.11:2375
  └ ID: PK2P:YTKT:Z5KW:OFBL:FTFI:X7GV:SY2L:T7CZ:EJ72:6ZDO:SZQV:AWR5
  └ Status: Healthy
  └ Containers: 1
  └ Reserved CPUs: 0 / 4
  └ Reserved Memory: 0 B / 4.053 GiB
  └ Labels: executiondriver=native-0.2, kernelversion=4.1.21-14-default, operatingsystem=openSUSE Leap 42.1 (x86_64), storagedriver=devicemapper
  └ UpdatedAt: 2016-06-05T05:05:16Z
  └ ServerVersion: 1.9.1
 node2: 10.10.10.12:2375
  └ ID: LUBR:4MRH:FJHK:6USE:B7GP:JOYU:HMAO:25ZF:IMVZ:65VA:QAN5:RJ47
  └ Status: Healthy
  └ Containers: 1
  └ Reserved CPUs: 0 / 4
  └ Reserved Memory: 0 B / 4.053 GiB
  └ Labels: executiondriver=native-0.2, kernelversion=4.1.21-14-default, operatingsystem=openSUSE Leap 42.1 (x86_64), storagedriver=devicemapper
  └ UpdatedAt: 2016-06-05T05:04:47Z
  └ ServerVersion: 1.9.1
Kernel Version: 4.1.21-14-default
Operating System: linux
CPUs: 8
Total Memory: 8.105 GiB
Name: swarm-manager

6. Di node0 buat overlay network untuk komunikasi antar container sekalipun berada di node berbeda.
# docker -H :4000 network create --driver overlay --subnet=172.31.0.0/16 overlay
# docker -H :4000 network ls
# docker -H :4000 network inspect overlay

7. Di node0 uji jalankan 2 container busybox dan uji konektivitas antar container melalui overlay network.
# docker -H :4000 run -d --name busybox1 -h busybox1 --net=overlay busybox init
# docker -H :4000 run -d --name busybox2 -h busybox2 --net=overlay busybox init
# docker -H :4000 ps -a
# docker -H :4000 inspect busybox2 | grep "172.31."
# docker -H :4000 exec -ti busybox1 ping -c 5 172.31.XXX.XXX

8. Di node0 jalankan shipyard untuk manajemen cluster melalui antarmuka web.
# docker run -ti -d --restart=always -h shipyard-rethinkdb --name shipyard-rethinkdb rethinkdb
# docker run -ti -d --restart=always --name shipyard-controller -h shipyard-controller --link shipyard-rethinkdb:rethinkdb --link swarm-manager:swarm -p 8080:8080 shipyard/shipyard:latest server -d tcp://swarm:4000

9. Buka peramban web dan akses ke alamat http://10.10.10.10:8080. Masuk dengan nama pengguna: admin dan kata sandi: shipyard.