Home > System Tutorial > LINUX > Add worker nodes to Docker engine Swarm!

Add worker nodes to Docker engine Swarm!

WBOY
Release: 2023-12-28 11:05:14
forward
1150 people have browsed it
Introduction Let's continue the work we started a few weeks ago in CentOS 7.2. In this guide, we learned how to initialize and launch the native clustering and orchestration capabilities built into Docker 1.12. But we only have the manager node and no other worker nodes. Today we will expand on this.

I'm going to show you how to add asymmetric nodes to Sawrm, say a Fedora 24 next to CentOS, and they will both join the cluster, with all the cool load balancing and stuff. Of course it won't be a breeze and we'll encounter some obstacles, so it should be pretty fun.
Docker 引擎的 Swarm中添加工作者节点!

Teaser

prerequisites

Before successfully adding other nodes to Swarm, we need to do several things. Ideally, all nodes should be running the same version of Docker, which should be at least 1.12 to support native orchestration capabilities. Like CentOS, Fedora's built-in repository does not have the latest build version, so you need to build manually, or use the Docker repository to manually add and install the correct version and fix some dependency conflicts. I've already shown you how to do it in CentOS and the process is the same.
Additionally, all nodes need to be able to communicate with each other. This requires correct routing and firewall rules so that managers and worker nodes can communicate with each other. Otherwise, you cannot add the node to Swarm. The easiest fix is ​​to temporarily clear the firewall rules (iptables -F), but this may compromise your security. Please make sure you fully understand what you are doing and create the correct rules for your nodes and ports.

Error response from daemon: Timeout was reached before node was joined. The attempt to join the swarm will continue in the background. Use the "docker info" command to see the current swarm status of your node.

Error response from daemon: Timed out before node joined. Attempts to join the Swarm will continue in the background. Use the “docker info” command to view the current Swarm status of the node.

You need to provide the same Docker image on the host machine. In the previous tutorial we created an Apache image, you need to do the same on your worker nodes or distribute the created image. If you don't do this, you will encounter errors. If you need help setting up Docker, read my introductory guide and web tutorial.

7vwdxioopmmfp3amlm0ulimcu \_ websky.11 my-apache2:latest
localhost.localdomain Shutdown Rejected 7 minutes ago
"No such image: my-apache2:lat&"
Copy after login
Start now

Now we have a CentOS machine booted and the container successfully created. You can connect to the service using the host port and it all looks fine. Currently, your Swarm only has managers.
Docker 引擎的 Swarm中添加工作者节点!

Manager

Join worker

To add new nodes, you need to use the join command. But you must first provide the token, IP address, and port so that the worker node can properly authenticate to the Swarm manager. Then (on Fedora) execute:

[root@localhost ~]# docker swarm join-token worker
To add a worker to this swarm, run the following command:
docker swarm join \
--token SWMTKN-1-0xvojvlza90nrbihu6gfu3qm34ari7lwnza ... \
192.168.2.100:2377
Copy after login

If you don't fix the firewall and routing rules, you will get timeout errors. If you have already joined the Swarm, you will receive an error if you repeat the join command:

Error response from daemon: This node is already part of a swarm. Use "docker swarm leave" to leave this swarm and join another one.
Copy after login

If in doubt, you can leave the Swarm and try again:

[root@localhost ~]# docker swarm leave
Node left the swarm.
docker swarm join --token
SWMTKN-1-0xvojvlza90nrbihu6gfu3qnza4 ... 192.168.2.100:2377
This node joined a swarm as a worker.
Copy after login

In the worker node, you can use docker info to check the status:

Swarm: active
NodeID: 2i27v3ce9qs2aq33nofaon20k
Is Manager: false
Node Address: 192.168.2.103
Likewise, on the manager:
Swarm: active
NodeID: cneayene32jsb0t2inwfg5t5q
Is Manager: true
ClusterID: 8degfhtsi7xxucvi6dxvlx1n4
Managers: 1
Nodes: 3
Orchestration:
Task History Retention Limit: 5
Raft:
Snapshot Interval: 10000
Heartbeat Tick: 1
Election Tick: 3
Dispatcher:
Heartbeat Period: 5 seconds
CA Configuration:
Expiry Duration: 3 months
Node Address: 192.168.2.100
Copy after login
Create or scale a service

Now, we need to look at whether and how Docker distributes containers among nodes. My tests demonstrate a fairly simple balancing algorithm under very light loads. After trying it once or twice, Docker was not reassigning running services to new workers, even after I tried scaling and updating. Likewise, at one point, it creates a new service on the worker node. Maybe this is the best option.
Docker 引擎的 Swarm中添加工作者节点!

Scale service

Docker 引擎的 Swarm中添加工作者节点!

Service ls

Docker 引擎的 Swarm中添加工作者节点!

Services ls, more

Docker 引擎的 Swarm中添加工作者节点!

Completely create a new service on the new worker node.

After a while, there is some redistribution of existing services between the two containers, but this takes some time. The new service works fine. This is just an early observation, so I can't say more right now. Now is the time to start exploring and adjusting.
Docker 引擎的 Swarm中添加工作者节点!

Load balancing worked after a while.

Summarize

Docker is a nimble little beast that continues to grow, becoming more complex, powerful, and certainly more elegant. It was only a matter of time before it was eaten up by a big business. Swarm mode works well when it brings native orchestration capabilities, but it goes beyond just a few containers and takes full advantage of its algorithms and scalability.

My tutorial shows how to add a Fedora node to a cluster run by CentOS and have the two work in parallel. There are still some questions about load balancing, but that's something I'll explore in a future article. All in all, I hope this is a lesson worth remembering. We've gone over some of the prerequisites and common issues you might encounter when trying to set up Swarm, we've launched a bunch of containers, and we've even briefly covered how to scale and distribute services. Remember, this is just the beginning.

cheers.

About the Author:

I am Igor Ljubuncic. Now about 38, married but no kids. I am now working as a chief engineer in a bold and innovative cloud technology company. Until about early 2015, I was working as a systems architecture engineer at one of the world's largest IT companies, working with an engineering computing team to develop new Linux-based solutions, optimize the kernel, and solve Linux problems. Before that, I was a technical lead on a team designing innovative solutions for high-performance computing environments. There are other fancy titles, including systems specialist, systems programmer, and more. All of this was once a hobby of mine, but starting in 2008 became my paid job. What could be more satisfying?

From 2004 to 2008, I made a living by working as a physicist in the medical imaging industry. My work expertise focuses on problem solving and algorithm development. For this purpose I use Matlab extensively, mainly for signal and image processing. Additionally, I am certified in several major engineering methodologies, including MEDIC Six Sigma Green Belt, Design of Experiments, and Statistical Engineering.

I also started writing books, both fantasy and technical work on Linux. Blending with each other.

To see a complete list of my open source projects, publications, and patents, scroll below.

For the complete list of my awards, nominations, and IT-related certifications, please wait.

The above is the detailed content of Add worker nodes to Docker engine Swarm!. For more information, please follow other related articles on the PHP Chinese website!

source:linuxprobe.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template