Docker Swarm cluster

Docker swarm adalah container orchestration dan clustering tool untuk mengatur Docker hosts, yang merupakan bagian dari Docker engine. Yang merupakan original clustering yang dibuat dan disediakan oleh Docker sehingga menjamin High Availability dan High Performance aplikasi yang jalan.

Kali ini kita akan mencoba docker swarm dengan topologi seperti berikut

Docker1 (192.168.192.45) sebagai manager kemudian docker2 (192.168.192.47) dan docker3 (192.168.192.46) sebagai workernya. Semua server menggunakan OS Ubuntu 18.04.

Konfigurasi hosts di semua node docker

Edit file /etc/hosts disemua server, dan tambahkan syntax berikut

192.168.192.45 docker1
192.168.192.47 docker2
192.168.192.46 docker3

Coba ping dari node docker1 ke docker2 atau docker3, lakukan sebaliknya juga

[email protected]:~$ ping docker2
PING docker2 (192.168.192.47) 56(84) bytes of data.
64 bytes from docker2 (192.168.192.47): icmp_seq=1 ttl=64 time=0.308 ms
64 bytes from docker2 (192.168.192.47): icmp_seq=2 ttl=64 time=0.318 ms
64 bytes from docker2 (192.168.192.47): icmp_seq=3 ttl=64 time=0.350 ms
^C
--- docker2 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2031ms
rtt min/avg/max/mdev = 0.308/0.325/0.350/0.023 ms
[email protected]:~$ ping docker3
PING docker3 (192.168.192.46) 56(84) bytes of data.
64 bytes from docker3 (192.168.192.46): icmp_seq=1 ttl=64 time=0.521 ms
64 bytes from docker3 (192.168.192.46): icmp_seq=2 ttl=64 time=0.555 ms
64 bytes from docker3 (192.168.192.46): icmp_seq=3 ttl=64 time=0.574 ms
^C
--- docker3 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2052ms
rtt min/avg/max/mdev = 0.521/0.550/0.574/0.021 ms

Install dan menjalankan Docker Service di semua node docker

Update dan upgrade apt

# apt update && apt upgrade -y

Install paket untuk meng”allow” apt dapat digunakan melalui https

# apt-get install apt-transport-https ca-certificates curl software-properties-common -y

Tambahkan Docker GPG key dan set repositorinya

# curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
# add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"

Install Docker CE versi terbaru

# apt-get install docker-ce

Enable docker service agar dapat jalan otomatis setiap server booting/direstart, kemudian start docker service

# systemctl enable docker
# systemctl start docker

Agar docker bisa dijalan pada user biasa (bukan root), gunakan command

# usermod -aG docker <username>

Pada lab kali ini saya menggunakan user ubuntu

# usermod -aG docker ubuntu

Sekarang kita coba menjalankan docker hello-world menggunakan user biasa

[email protected]:/home/ubuntu# su - ubuntu
[email protected]:~$ docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
1b930d010525: Pull complete
Digest: sha256:2557e3c07ed1e38f26e389462d03ed943586f744621577a99efb77324b0fe535
Status: Downloaded newer image for hello-world:latest
Hello from Docker!
This message shows that your installation appears to be working correctly.
To generate this message, Docker took the following steps:
The Docker client contacted the Docker daemon.
The Docker daemon pulled the "hello-world" image from the Docker Hub.
(amd64)
The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
The Docker daemon streamed that output to the Docker client, which sent it
to your terminal.
To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash
Share images, automate workflows, and more with a free Docker ID:
https://hub.docker.com/
For more examples and ideas, visit:
https://docs.docker.com/get-started/

Konfigurasi Docker1 Node untuk Inisialisasi Swarm Cluster

Sekarang kita akan membuat swram cluster untuk ketiga node. Untuk membuatnya, memerlukan inialisasi pada dockermanager node (pada lab ini docker1 sebagai manager) kemudian dockerworker (docker2 dan docker3) untuk join cluster.

docker swarm init –advertise-addr <manager node IP address>

[email protected]:~$ docker swarm init --advertise-addr 192.168.192.45
Swarm initialized: current node (ifoxr4e0uvx75wjoa5x38ebn5) is now a manager.
To add a worker to this swarm, run the following command:
docker swarm join --token SWMTKN-1-0oxl56zp3d6uafxq21tk6pyblh4a1d2l7v6nfod0cl1f6d6wa6-40ptwffkqc8ynp07urtgkdl35 192.168.192.45:2377
To add a manager to this swarm, run 'docker swarm join-token manager' and follow the instructions.
[email protected]:~$

Pada hasil diatas, join token sudah digenerate oleh dockermanager, ini nanti digunakan untuk join dockerworkers

Konfigurasi Docker2 dan Docker3 Node untuk join Swarm Cluster

Dari hasil join token diatas, ketikkan command diatas tadi ke docker2 dan docker3

[email protected]:~$ docker swarm join --token SWMTKN-1-0oxl56zp3d6uafxq21tk6pyblh4a1d2l7v6nfod0cl1f6d6wa6-40ptwffkqc8ynp07urtgkdl35 192.168.192.45:2377
This node joined a swarm as a worker.
[email protected]:~$ docker swarm join --token SWMTKN-1-0oxl56zp3d6uafxq21tk6pyblh4a1d2l7v6nfod0cl1f6d6wa6-40ptwffkqc8ynp07urtgkdl35 192.168.192.45:2377
This node joined a swarm as a worker.

Verifikasi Swarm Cluster

Untuk melihat status node menggunakan command berikut di dockermanager

[email protected]:~$ docker node ls
ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS ENGINE VERSION
ifoxr4e0uvx75wjoa5x38ebn5 * docker-1 Ready Active Leader 18.09.3
2ar0x7l132sxmvdpxyijd7r4p docker-2 Ready Active 18.09.3
moxtattg9gmsigwhgxk2rzh9s docker-3 Ready Active 18.09.3

Apabila kehilangan join token, bisa menggunakan command

docker swarm join-token manager -q

docker swarm join-token worker -q

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.