Docker Swarm

Docker Swarm

Docker Swarm

Hello Everyone

Welcome to CloudAffaire and this is Debjeet.

In the last blog post, we have discussed docker compose.

https://cloudaffaire.com/docker-compose/

In this blog post, we will discuss docker swarm. We will also configure our 1st docker swarm cluster.

What is Docker Swarm?

The cluster management and orchestration features embedded in the Docker Engine are built using swarmkit. Swarmkit is a separate project which implements Docker’s orchestration layer and is used directly within Docker.

A swarm consists of multiple Docker hosts which run in swarm mode and act as managers (to manage membership and delegation) and workers (which run swarm services). A given Docker host can be a manager, a worker, or perform both roles. When you create a service, you define its optimal state (number of replicas, network and storage resources available to it, ports the service exposes to the outside world, and more). Docker works to maintain that desired state. For instance, if a worker node becomes unavailable, Docker schedules that node’s tasks on other nodes. A task is a running container which is part of a swarm service and managed by a swarm manager, as opposed to a standalone container.

One of the key advantages of swarm services over standalone containers is that you can modify a service’s configuration, including the networks and volumes it is connected to, without the need to manually restart the service. Docker will update the configuration, stop the service tasks with the out of date configuration, and create new ones matching the desired configuration.

Up until now, you have been using Docker in a single-host mode on your local machine. But Docker also can be switched into swarm mode, and that’s what enables the use of swarms. Enabling swarm mode instantly makes the current machine a swarm manager. From then on, Docker runs the commands you execute on the swarm you’re managing, rather than just on the current machine.

Docker Swarm components:

  • Nodes: A node is an instance of the Docker engine participating in the swarm. You can also think of this as a Docker node. You can run one or more nodes on a single physical computer or cloud server, but production swarm deployments typically include Docker nodes distributed across multiple physical and cloud machines.
    • Manager Node: To deploy your application to a swarm, you submit a service definition to a manager node. Manager node are the only machines in a swarm that can execute your commands or authorize other machines to join the swarm as workers.
    • Worker Node: Worker nodes are just there to provide capacity and do not have the authority to tell any other machine what it can and cannot do.
  • Services: A service is the definition of the tasks to execute on the manager or worker nodes. It is the central structure of the swarm system and the primary root of user interaction with the swarm.
  • Task: A task carries a Docker container and the commands to run inside the container. It is the atomic scheduling unit of swarm. Manager nodes assign tasks to worker nodes according to the number of replicas set in the service scale. Once a task is assigned to a node, it cannot move to another node. It can only run on the assigned node or fail.
  • Load Balancing: The swarm manager uses ingress load balancing to expose the services you want to make available externally to the swarm. The swarm manager can automatically assign the service a PublishedPort or you can configure a PublishedPort for the service. You can specify any unused port. If you do not specify a port, the swarm manager assigns the service a port in the 30000-32767 range. Swarm mode has an internal DNS component that automatically assigns each service in the swarm a DNS entry. The swarm manager uses internal load balancing to distribute requests among services within the cluster based upon the DNS name of the service.

Next, we will create a 3 node docker swarm.

Prerequisite for this demo:

  • Three AWS EC2 AWS Linux 2 instances or local centos instances which can communicate over a network.
  • Docker Engine 1.12 or later installed in all three nodes
  • Open ports between the hosts
    • TCP port 2377 for cluster management communications
    • TCP and UDP port 7946 for communication among nodes
    • UDP port 4789 for overlay network traffic

I am using my VirtualBox centos VM’s for this demo and below is the configuration. But you can use any system consisting of multiple instances with network connectivity.

Docker Swarm Demo:

Docker Swarm

Hope you have enjoyed this article. In this demo, we have only configured docker swarm but did not deploy any application in it. In the next demo, we will deploy an application using docker service.

To get more details on docker, please refer below docker documentation.

https://docs.docker.com/

 

Leave a Reply

Close Menu