Please go through the "Docker Swarm Single Master" configuration if you are new to this concept.
URL: https://sltechgeekx.blogspot.com/2020/07/docker-swarm.html
Docker Swarm With Multi-Master
If the swarm loses the quorum of managers, the swarm cannot perform management tasks. If your swarm has multiple managers, always have more than two. To maintain quorum, a majority of managers must be available. An odd number of managers is recommended, because the next even number does not make the quorum easier to keep. For instance, whether you have 3 or 4 managers, you can still only lose 1 manager and maintain the quorum. If you have 5 or 6 managers, you can still only lose two.
Even if a swarm loses the quorum of managers, swarm tasks on existing worker nodes continue to run. However, swarm nodes cannot be added, updated, or removed, and new or existing tasks cannot be started, stopped, moved, or updated.
You should maintain an odd number of managers in the swarm to support manager node failures.
Configurations
In this example we need 5 servers.
Manager Node --> 3
Worker Node --> 2
Manager-1 --> 192.168.1.131
Manager-2 --> 192.168.1.132
Manager-3 --> 192.168.1.133
Worker-1 --> 192.168.1.134
Worker-2 --> 192.168.1.135
Step 1
Install and enable docker service in each servers
yum install docker-ce docker-ce-cli containerd.io
systemctl enable docker
systemctl start docker
Step 2
Configure docker swarm in manager-1 node
docker swarm init --advertise-addr 192.168.1.131
Step 3
Add Worker Node to docker swarm. You will get join token for worker nodes from above command.
docker swarm join --token SWMTKN-1-17drizdszlt8ftwnw4nzafrmv9h0cjp9f53dcwm10kk52baulp-44vv9fwo8upmoba3j1vxcruro 192.168.1.131:2377
Step 4
Add Manager Nodes to docker swarm
Execute below command to generate manager token
docker swarm join-token manager
Execute the join token in each manager nodes.
docker swarm join --token SWMTKN-1-17drizdszlt8ftwnw4nzafrmv9h0cjp9f53dcwm10kk52baulp-bvfss1vww7caykf6tfk23ijg9 192.168.1.131:2377
To verify the docker nodes execute below command.
docker node ls
Step 5
Create Docker Service
Here I am using nginx docker image to create docker image. Initially I am creating five docker-nginx containers and expose port 80 and 443 for out side. Also I am limit the memory and CPU for each containers.
docker service create --limit-cpu 1 --limit-memory 500MB --replicas 5 -p 80:80 -p 443:443 --hostname=docker-nginx.local --name docker-nginx nginx
To verify the docker service
docker service ls
You can type manager IP to load the webserver default page.
http://192.168.1.131/
Checking high availability of the Docker Swarm
As pet the below image, we have 3 manager nodes and "Leader" is manager-1.
Now we are going to shutdown the manager-1 node.
After Shutdown the manager-1, you can verify docker swarm node status by executing below command.
Now our new leader is manager-2









No comments:
Post a Comment