
Docker Swarm is a container orchestration tool. That is, it allows for creation of a cluster of docker hosts and turns them into a single virtual server. This enables your application running on containers achieve high performance and high availability by distributing it between available hosts within the cluster. You will learn how to install and configure docker swarm in this article.
For whichever number of servers deployed, one will be the manager node and the rest worker nodes. Manager node handles all cluster management tasks while the worker nodes run the containers. In this article, we will use two nodes, for example:
SSH to all Ubuntu server as a non-root user with sudo access.
Edit host file /etc/hosts in all the nodes.
Add the following code in the file.
Ping all the nodes using their hostnames.
Install Docker CE on all the nodes. Perform all stages in this step on all nodes.
Update the system packages.
Install all required packages.
Install Docker repository signing keys.
Add the Docker repository.
Update the system packages.
Install Docker CE.
Confirm the status of Docker.
Enable the Docker service to automatically run at system boot.
Add your current user to docker group.
To create a Docker Swarm cluster, you will first need to initialize the swarm mode on the manager node. Then, join the worker nodes to the cluster. Strictly use the nodes IP address.
Initialize the swarm mode.
Go to the worker-1 node and add it to the cluster. Modify the --token value with your own.
Go to the manager node and verify if all the worker nodes successfully joined the cluster.
Go to the manager node and create a 'Docker getting started web-page' service named docker-tutorial that will run on default http port 80 and expose it to port 80 on the host server.
Verify the status of the created service.
With two nodes in our cluster, we will make two replicas of the service. This will enable access to the service form both the manager and worker nodes.
Create replicas.
Verify the status of the service replicas.
Go to your browser and access the service from all your nodes. For example:
manager node.
worker-1 node.
You have successfully installed and configured Docker Swarm. You can now scale your application by adding more worker nodes to the cluster and creating more replicas of the services you have running.
0 Comments
Be the first to comment and share your perspective with the community.