Setup Docker Swarm (centos 7)
Requirements :
- 1 machine master
- 2 machines as workers
Presentation
Setup & introduce to the features of Docker Swarm
Plan :
- Setup master swarm
- Install docker into centos 7
- Start Docker
- Assign Ip address to the manager swarm
- Open protocols and ports between the hosts
- init SWARM
- Adding nodes to the swarm
- Install docker into centos 7
- Start Docker
- Add a worker to the swarm
- Manager “node ls” command to see the worker nodes:
1. Setup master swarm
- Install docker for centos 7
$ yum install -y yum-utils
$ yum-config-manager - add-repo https://download.docker.com/linux/centos/docker-ce.repo
$ yum install docker-ce docker-ce-cli containerd.io
b.Start Docker
$ systemctl start docker
c. Assign Ip address to the manager swarm
The ip address of the manager machine (Master :67.205.189.189)
The IP address must be assigned to a network interface available to the host operating system. All nodes in the swarm need to connect to the manager at the IP address.
d. Open protocols and ports between the hosts
The following ports must be available. On some systems, these ports are open by default.
- TCP port 2377 for cluster management communications
- TCP and UDP port 7946 for communication among nodes
- UDP port 4789 for overlay network traffic
e. init SWARM
$ docker swarm init — advertise-addr 67.205.189.189
2 Add nodes to the swarm
Once you’ve created a swarm with a manager node, you’re ready to add worker nodes.
- Install docker for centos 7
$ yum install -y yum-utils
$ yum-config-manager - add-repo https://download.docker.com/linux/centos/docker-ce.repo
$ yum install docker-ce docker-ce-cli containerd.io
- Start Docker
$ systemctl start docker
- Add a worker to the swarm
To add a worker to this swarm, run the following command:
docker swarm join-token worker
Example :
Machine Master
[root@masterswarm ~]# docker swarm join-token worker
docker swarm join - token SWMTKN-1–5lscx6vk8jobgiw4fvr14aw359i3ma3wzs279af4ch8u9cqOOy-41gx6iw1bgjnllz0v0cy3h2tc 67.205.189.189:2377
Machine Worker
[root@worker1 ~]# docker swarm join — token SWMTKN-1–5lscx6vk8jobgiw4fvr14aw359i3ma3wzs279af4ch8u9cqOOy-41gx6iw1bgjnllz0v0cy3h2tc 67.205.189.189:2377
This node joined a swarm as a worker.
3 Manager “node ls” command to see the worker nodes:
Manager “node ls” command to see the worker nodes:
[root@masterswarm ~]# docker node ls
pm8x8qoowdp0lzppmn3ujnbyy worker1 Ready Active 19.03.13
e6a7hj998sr8a9xqfso0r3i6a worker2 Ready Active 19.03.13
Now your swarm consists of a manager and two worker nodes.
Hope this will help!
if you like my article :
NHAILA Achraf
#devsecops #devops #dockerswarm #swarm #cluster