OpenSource For You

Get Acquainted with Docker Swarm

The use of Docker containeri­sation has become quite common, especially in production. Docker Swarm is a clustering and scheduling tool for Docker containers. With the help of Swarm, sysadmins can deploy and manage a cluster of Docker nodes as a single vir

- By: Neetesh Mehrotra The author works at NIIT Technologi­es as a senior test engineer. His areas of interest are Java developmen­t and automation testing. He can be contacted at mehrotra.neetesh@gmail.com.

Docker is a tool that’s intended to make the process of creating, deploying and running applicatio­ns easier by using container based virtualisa­tion technology. Docker is open source container technology that provisions far more apps running on the same old servers compared to traditiona­l VMs.

The Docker engine

The Docker engine is the core component responsibl­e for creating Docker images and running them as services.

The core components of the Docker engine are:

The Docker daemon

This is a continuous running program (daemon) that manages the service and other Docker objects tied to it.

The REST API

This specifies interfaces that programs can use to speak to the daemon and directs what it should do.

The Docker client

This is used to interact with the daemon (Docker command).

Docker networking

Docker networking comes into the picture in large scale, real-time scenarios. Docker networking helps us to share data across various containers.

The host and containers in Docker are linked on the basis of a 1:N relationsh­ip, which means one host can command multiple containers.

Cluster management

Before we get into the details of Docker Swarm, let us understand some of the basic concepts of a cluster.

Cluster management is a technique to manage one or more cluster nodes. This is done using a cluster manager and agent. A cluster manager is nothing but a GUI or CLI software.

The clustering tool

A clustering tool is software that manages a set of resources through a single point of command. In our case, these sets of resources are nothing but containers. For example, workload distributi­on management across a distribute­d system/cluster is very tedious for large enterprise systems. The clustering tool eases matters by automating this task. The instructor will just specify the details such as the cluster’s size, settings and some advanced features. Everything else is taken care of by the clustering tool. Docker Swarm is one such example of a clustering tool for containers.

The need for a container orchestrat­ion system

Container management becomes very tough in case of a large scale distribute­d system which involves hundreds of containers. A few of the key activities are:

Scaling the number of containers based on the peak load Performing rolling updates for containers

Performing health checks on containers

Docker Swarm is a cluster management and orchestrat­ion tool which is inbuilt in the Docker engine. A Swarm is a cluster of Docker engines, or nodes, with which you deploy services.

You can build this using the SwarmKit (a toolkit to orchestrat­e the system). Swarm mode can be enabled by either initialisi­ng a Swarm or joining an existing Swarm.

How Docker Swarm evolved

In early 2014, Docker developed a cluster management system with a communicat­ion protocol known as Beam.

Later, with the Docker API, a daemon was introduced to communicat­e with a distribute­d system. This was named Libswarm. The daemon is called Swarmd.

In November 2014, the Docker team retained the concept of cluster communicat­ion with additional remote APIs and named this Swarm. This first generation was called Swarm v1.

In February 2016, Swarm v1 was completely redesigned to overcome certain limitation­s and was named Swarm v2. In June 2016, SwarmKit, which is an orchestrat­ion toolkit within the Docker engine for distribute­d service, came into being. This version is also known as ‘Swarm mode’.

Features of Docker Swarm

The features of Docker Swarm are:

Decentrali­sed design: You can manage the nodes in the Swarm cluster through Swarm commands. This gives a single point of access to build the entire Swarm.

Scaling: You can specify the number of tasks for every service. This is automatica­lly done through commands to scale the service.

Desired state reconcilia­tion: The Swarm manager keeps track of the cluster state so that the actual and the desired state is always the same.

Multi-host networking: When you specify an overlay network to connect your services, the Swarm manager assigns addresses to the containers on the overlay network once you create/update the containers.

Service discovery: Swarm manager nodes allocate a unique DNS name for the services. You will be able to find containers in the swarm through the DNS server embedded in the swarm.

Load balancing: SwarmKit has an internal load balancer which distribute­s the service containers within nodes. You can include an external load balancer as well.

Before we dive into the architectu­re of Swarm, let’s look at some of the key concepts in Docker Swarm. Docker node

Docker service

Docker tasks

Docker Node

Docker Node is a Docker engine instance that is included in Docker Swarm. In real-time, these nodes are distribute­d across multiple clouds as well as physical machines.

There are two kinds of Docker nodes:

Manager node

Worker node

Manager node: The manager node is responsibl­e for all the orchestrat­ion and container management activities required to keep up the desired system state.

Worker node: The worker node executes the tasks assigned by the manager node.

Docker service

Service is nothing but a task definition that has to be executed. You will have to create a service specifying the image name and other additional parameters. In most cases, service is an image for a microservi­ce of some large applicatio­n. An example would be an HTTP server or a database, any kind of executable program that you would run in a distribute­d system, etc.

Architectu­re

The node is the key member of a Docker Swarm. A Swarm can have more than one manager node. In this case, the nodes elect their leader using the Raft algorithm to conduct the orchestrat­ion tasks.

Manager nodes are also worker nodes. But you can configure them as manager-only nodes, thereby restrictin­g them from working on any other tasks.

The Docker Swarm API is another key component of the Docker Swarm architectu­re.

Swarm has a list of remote APIs similar to Docker. This enables all kinds of Docker clients to connect to Swarm. In addition, the Swarm API provides the cluster informatio­n as well.

Docker API informatio­n is restricted to one single

Docker engine, whereas the Docker Swarm API provides the informatio­n on the cluster of engines, the number of nodes available in a cluster, and the node details.

Raft Consensus

Manager nodes use the Raft Consensus Algorithm to internally manage the cluster state.

This is to ensure that all manager nodes that are scheduling and controllin­g tasks in the cluster maintain/store a consistent state.

Docker Swarm: Commands

Let us now get acquainted with Docker Swarm commands. To initialise Swarm, use the following command:

docker swarm init

Note: You can configure the manager node to publish its address as a manager with the mentioned IP address, as shown below:

docker swarm init --advertise-addr <ip-address> For Docker Swarm Help, use the following command: docker swarm --help

The above command lists the basic Swarm commands with their usage details.

To list the number of nodes currently available in the Swarm, use the following command:

docker node ls

Deploying a service with constraint­s

You can add your own constraint­s while deploying a service. This will ensure that the service will get scheduled as a task only when the constraint is met. This constraint is known as placement.

In the following example, you add a constraint to deploy a service only on nodes where there is SSD storage.

docker service create --name testServic­e --replicas 2 --constraint node.labels.disk==ssd tomcat

 ??  ??
 ??  ??
 ??  ?? Figure 2: Docker Swarm architectu­re
Figure 2: Docker Swarm architectu­re
 ??  ?? Figure 1: The Docker network
Figure 1: The Docker network

Newspapers in English

Newspapers from India