How to install Docker Swarm cluster on Debian 10
You can download this article in PDF format via the link below to support us.
Download the guide in PDF formatshut down
Docker Swarm is a tool for orchestrating Docker hosts. We can create highly available and high-performance Docker clusters and distribute applications among hosts.
Docker swam uses a manager host and worker node architecture. You can have one or more Manager nodes in your docker swarm cluster. The manager node uses the native Docker API and shares the database of the Docker Swarm cluster with the auxiliary nodes. The manager host maintains the cluster state, schedules tasks, and handles HTTP API endpoints.
A worker node is an instance of the Docker engine that executes the container.
Compared with Kubernetes which has complete functions such as monitoring, entry and volume, Docker swarm has a simpler status. Docker Swarm also lacks automatic expansion capabilities, so containers cannot be automatically expanded based on monitoring and resource utilization. You must manually scale the container.
This guide will discuss how to set up a Docker Swarm cluster on a Debian 10 host.
Step 1-Node preparation
Configure the host name for each node in the host /etc/hosts
Used for local resolution files.
sudo vim /etc/hosts
Add detailed information about the nodes on each server, including the manager node and the auxiliary node.
10.31.45.182 manager
10.31.45.226 worker-01
10.31.45.219 worker-02
Ensure that the hosts can reach each other through ping.
Step 2-Install Docker CE on Debian 10
We need to install the Docker engine on all hosts, managers and secondary nodes.
Install the dependency package on the host:
sudo apt-get update
sudo apt-get install apt-transport-https ca-certificates curl gnupg-agent software-properties-common
Add the Docker GPG key:
curl -fsSL https://download.docker.com/linux/debian/gpg | sudo apt-key add -
Add the Docker repository:
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/debian $(lsb_release -cs) stable"
Install Docker engine
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli
Start and enable Docker
sudo systemctl start docker
sudo systemctl enable docker
Add your user to the Docker group
sudo usermod -aG docker ${USER}
Step 3-Initialize the Docker Swarm cluster
In this step, we need to initialize the Docker cluster mode on the manager node, and then we can add worker nodes later.
The following command is used to initialize Docker Swarm Manager.You should replace
newgrp docker
sudo docker swarm init --advertise-addr <manager-IP>
Sample output:
$ docker swarm init --advertise-addr 10.31.45.182
Swarm initialized: current node (xj5sqdpsbs5x2pgt670dft31m) is now a manager.
To add a worker to this swarm, run the following command:
docker swarm join --token SWMTKN-1-5yat7zlum78qmnlhv1vs0b0k4c42jafh5kt8xtb36eara4c5ip-490dr4yhpbe5qnic476wh90zg 10.31.45.182:2377
To add a manager to this swarm, run 'docker swarm join-token manager' and follow the instructions.
After initializing the manager node, we can now add worker nodes using the connection token provided in the example above.
$ docker swarm join --token SWMTKN-1-5yat7zlum78qmnlhv1vs0b0k4c42jafh5kt8xtb36eara4c5ip-490dr4yhpbe5qnic476wh90zg 10.31.45.182:2377
This node joined a swarm as a worker.
We can use the following command to check whether the secondary node has successfully joined the cluster:
sudo docker node ls
Sample output:
$ docker node ls
ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS ENGINE VERSION
h673oapwzqcsoszm36dcsyx4u worker-01 Ready Active 20.10.3
tg30e58pf2ebktyu5geg5hjzd worker-02 Ready Active 20.10.3
vhqes84cz4ljrrj8ux9bx9jzv worker-03 Ready Active 20.10.3
xj5sqdpsbs5x2pgt670dft31m * manager Ready Active Leader 20.10.3
Deploy the application on Docker Swarm
Here, we will deploy a web application on the cluster.
$ docker service create --name webserver -p 8080:80 nginx
The above command deploys the Nginx application on the cluster and exposes it on port 8080.
To confirm whether the service is running:
$ docker service ls
ID NAME MODE REPLICAS IMAGE PORTS
z383boupqk5p webserver replicated 1/1 nginx:latest *:80->80/tcp
Scale the application on Docker Swarm
You can scale applications on Docker Swarm clusters to achieve high availability and high performance.
Use the following command:
$ docker service scale webserver=4
where is it Web server = 4 Is the name of the application, and is the maximum number of containers that can be used after copying.
You can verify the copy with the following command:
$ docker service ls
Sample output:
We have successfully deployed a Docker Swarm cluster on the Debian 10 host.
View other articles from this website;
How to install Docker Swarm on Ubuntu
How to run a local Kubernetes cluster in a Docker container
How to install Kubernetes cluster on Ubuntu using kubeadma
You can download this article in PDF format via the link below to support us.
Download the guide in PDF formatshut down