Analysis of the use and principle of Docker Swarm cluster management

Analysis of the use and principle of Docker Swarm cluster management

Swarm Cluster Management

Introduction

Docker Swarm is a cluster management tool for Docker. It turns a pool of Docker hosts into a single virtual Docker host. Docker Swarm provides the standard Docker API, so any tool that already communicates with the Docker daemon can use Swarm to easily scale to multiple hosts.

Supported tools include, but are not limited to, the following:

  • Dokku
  • Docker Compose
  • Docker Machine

principle

As shown in the figure below, the swarm cluster consists of a management node (manager) and a worker node (work node).

  • Swarm manager: Responsible for the management of the entire cluster, including cluster configuration, service management, and all other cluster-related tasks.
  • Work node: the available node in the figure, which is mainly responsible for running the corresponding services to execute tasks.

insert image description here

use

The following examples are all based on Docker Machine and VirtualBox. Make sure that VirtualBox has been installed on your host.

1. Create a swarm cluster management node (manager)

Create a docker machine:

$ docker-machine create -d virtualbox swarm-manager 

insert image description here

Initialize the swarm cluster. The machine that performs the initialization is the management node of the cluster.

$ docker-machine ssh swarm-manager
$ docker swarm init --advertise-addr 192.168.99.107 #The IP here is the IP assigned when the machine is created. 

insert image description here

The above output proves that initialization has been successful. You need to copy the following line, which will be used when adding working nodes:

docker swarm join --token SWMTKN-1-4oogo9qziq768dma0uh3j0z0m5twlm10iynvz7ixza96k6jh9p-ajkb6w7qd06y1e33yrgko64sk 192.168.99.107:2377

2. Create a swarm cluster worker node (worker)

Here we create two machines, swarm-worker1 and swarm-worker2.

insert image description here

Enter the two machines separately and specify to add to the cluster created in the previous step. The content copied in the previous step will be used here.

insert image description here

The above data output indicates that it has been added successfully.

In the figure above, the content copied in the previous step is relatively long and will be automatically truncated. The commands actually run in the figure are as follows:

docker@swarm-worker1:~$ docker swarm join --token SWMTKN-1-4oogo9qziq768dma0uh3j0z0m5twlm10iynvz7ixza96k6jh9p-ajkb6w7qd06y1e33yrgko64sk 192.168.99.107:2377

3. View cluster information

Enter the management node and execute: docker info to view the information of the current cluster.

$ docker info 

insert image description here

4. Deploy services to the cluster

Note: Any operations related to cluster management are performed on the management node.

The following example creates a service named helloworld on a worker node, which is randomly assigned to a worker node:

docker@swarm-manager:~$ docker service create --replicas 1 --name helloworld alpine ping docker.com 

insert image description here

5. Check service deployment

Check which node the helloworld service is running on and you can see that it is currently running on the swarm-worker1 node:

docker@swarm-manager:~$ docker service ps helloworld 

insert image description here

View the detailed information of helloworld deployment:

docker@swarm-manager:~$ docker service inspect --pretty helloworld 

insert image description here

6. Expanding cluster services

We will expand the above helloworld service to two nodes.

docker@swarm-manager:~$ docker service scale helloworld=2 

insert image description here

You can see that it has expanded from one node to two nodes.

insert image description here

7. Deleting Services

docker@swarm-manager:~$ docker service rm helloworld 

insert image description here

Check if it has been deleted:

insert image description here

8. Rolling upgrade service

In the following example, we will introduce how to perform a rolling upgrade of the redis version to a higher version.

Create a 3.0.6 version of redis.

docker@swarm-manager:~$ docker service create --replicas 1 --name redis --update-delay 10s redis:3.0.6 

insert image description here

Rolling upgrade of redis.

docker@swarm-manager:~$ docker service update --image redis:3.0.7 redis 

insert image description here

From the picture, we can see that the redis version has been upgraded from 3.0.6 to 3.0.7, indicating that the service has been upgraded successfully.

9. Stop a node from receiving new tasks

View all nodes:

docker@swarm-manager:~$ docker node ls 

insert image description here

It can be seen that all nodes are currently Active and can receive new task assignments.

Stop the node swarm-worker1:

insert image description here

Note: The state of swarm-worker1 changes to Drain. The cluster service will not be affected, but the swarm-worker1 node will no longer receive new tasks, and the cluster load capacity will decrease.

The node can be reactivated with the following command:

docker@swarm-manager:~$ docker node update --availability active swarm-worker1 

insert image description here

This is the end of this article about the use and principle analysis of Docker Swarm cluster management. For more relevant Docker Swarm cluster management content, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • How to use Docker Swarm to build WordPress
  • Example of using Docker Swarm to build a distributed crawler cluster
  • How to use Docker Swarm to build a cluster
  • Detailed explanation of using Docker 1.12 to build a multi-host Docker swarm cluster
  • How to install Docker and use it in Docker Swarm mode
  • Docker swarm simple tutorial

<<:  A brief discussion on four solutions for Vue single page SEO

>>:  MySQL 8.0.22 compressed package complete installation and configuration tutorial diagram (tested and effective)

Recommend

Summary of some points to note when registering Tomcat as a service

Here are some points to note when registering Tom...

Introduction to JavaScript Number and Math Objects

Table of contents 1. Number in JavaScript 2. Math...

Top 10 Js Image Processing Libraries

Table of contents introduce 1. Pica 2. Lena.js 3....

Detailed explanation of CocosCreator message distribution mechanism

Overview This article begins to introduce content...

Use of Linux read command

1. Command Introduction The read command is a bui...

Summary of Mathematical Symbols in Unicode

There are many special symbols used in mathematic...

Analysis of the implementation of MySQL statement locking

Abstract: Analysis of two MySQL SQL statement loc...

Quickly solve the problem of slow and stuck opening of input[type=file]

Why is it that when the input tag type is file an...

How to implement import and export mysql database commands under linux

1. Export the database using the mysqldump comman...

How to use nginx to intercept specified URL requests through regular expressions

nginx server nginx is an excellent web server tha...

The difference between html, xhtml and xml

Development Trends: html (Hypertext Markup Languag...