TP Docker Swarm

Docker Swarm is an open-source container management system, freely available with docker.

In this pratical class, we are going to:

- setup multi-node docker swarm Cluster on Ubuntu 20.20 server;

- deploy an application and manage it on our deployed docker swarm;

Prerequisites

Connection to your nodes

You must be connected to N7 with the VPN and be connected to a N7 machine with your studenID. Use the following commands to access your nodes :

Type your enseeiht password

Node1 port is 130XX and the node2 port 130XX+1

Where XX=01-40. This will give you acces to a VM with IP address 192.168.27.(XX+10) and the password is "toto"

Docker installation on both nodes

Docker must be installed on both node1 and node2. You start by installing all the required packages.

Swarm installation on node1 (Swarm manager)

Init swarm on node1

Save the join command on your terminal.

Type this command to get the list of nodes

To get the list of running service

Node2 configuration

Add the node2 to the cluster

On node1 check the number of nodes

Tomcat deployment **

We will deploy a Tomcat (as during the last class) in our swarm cluster. Create a new directory named 'tomcat' and move to the directory.

We will use the tomcat:v1 image of the last class and implement the same architecture as last class

image-20201006170634824

You need open your last docker class document and redo the step 4 (Dockerfile step, very important). This is to create the tomcat:v1 image.

We need to create a network mynet

Create a docker compose file named 'tomcat.yml' and paste the following content.

Start your tomcat service with

You can check on which node the container is started by using

Get the serviceID and

Connect to the node and check if a container is running

Check if the tomcat is available (wait for the container to start)

Stop the service

We will create a basic architecture with a single tomcat and single haproxy. You have to download haprox_backup.cfg file and modify it to add "tc1" in the server list (step 5 of docker class)

Create a file named architecture.yml with this content (this is a docker-compose syntax)

Now we can start the service

You can test your deployment (wait for all containers to start)

Stop the services

Redo all the previous operations with the container image tomcat:v1 and haprox_backup file also available on node2. You can observe that some of your containers will be deployed on node2.

Tomcat Deployment

You will demonstrate that you followed the session by deploying the tomcat architecture of last class in your swarm cluster (2 tomcats instance and 1 haproxy with the configuration).

Modify the architecture.yml file for that.

image-20201006170634824

Good luck!