Container Orchestration – Docker Swarm

  • By
  • March 26, 2022
  • Docker

Container Orchestration – Docker Swarm –

What is Container Orchestration?

Container Orchestration is the process of deploying and maintaining large number Operating System containers and services for the application to run as intended.

 It performed to control and automate tasks like:

– Deployment of Containers

– Scaling

– Resource allocation

– Load Balancing

– Health Monitoring  

For Free Demo classes Call: 7798058777

Registration Link: Click Here!

Docker Swarm:

Docker swarm is a container orchestration tool part of the docker engine. With swarm developers and IT administrators can deploy and manage a cluster of docker nodes as a single virtual system.

A Docker swarm is group of eighter physical or virtual machines that are running the docker application and that have been configured to join together in a cluster.

 

  1. Service :

Service defines the tasks that need to be executed on the manager and worker nodes.

 

  1. Tasks:

Tasks refer to the docker containers that execute the commands defined in the service.

 

  1. Manager Node:

The Manager node is responsible for:

– Accepting commands and creating service objects.

– Allocating IP addresses to tasks

– Assigning tasks to nodes

– Instructing a worker to run a task

 

  1. Worker Node:

Worker nodes are responsible for checking assigned tasks and executing containers.

Lab Setup:

Use here 3 system as follows (AMI Linux 2- AWS Cloud)

Node1: Manager (192.168.1.104)

Node2: Woker1 (192.168.1.105)

Node3: Worker2 (192.168.1.106)

 

Step1: Install docker on all node (Master and Workers)

For install docker 

#yum   update   -y

#yum    install    docker   -y

 

For show docker is installed or not

#docker    –version

 

For start docker service

#systemctl   start  docker

 

For permanent on docker

#systemctl   enable docker

 

For show docker service status

#systemctl   status docker

Step2: create docker manager and worker in swarm:

set hostname to manager system

#hostnamectl  set-hostname  manager

 

For create swarm manager

#docker swarm init –advertise-addr 192.168.1.104

or

#docker swarm init

 

Step3: Add worker in swarm:

open terminal of worker 

Worker1:

Set hostname to worker system

#hostnamectl  set-hostname  worker1

#docker swarm join –token SWMTKN-1-4g9ngsw1fluugei3zib5fa4udhyvwht04akk099dyj78lbi2qb-8lymhd7y4gjxvs0rikdt882ti 192.168.1.104:2377

 

Worker2:

Set hostname to worker system

#hostnamectl  set-hostname  worker2

#docker swarm join –token SWMTKN-1-4g9ngsw1fluugei3zib5fa4udhyvwht04akk099dyj78lbi2qb-8lymhd7y4gjxvs0rikdt882ti 192.168.1.104:2377

 

Step4: Verify worker add as a node or not:

Open terminal of manager system 

#docker  node   ls

For show help

#docker  swarm  –help

 

For create secondary Manager

#docker  swarm  join-token  manager

(add avbove token on system which you want to secondary manager system)

 

Check token for add more worker in manager system

#docker  swarm  join-token  worker

(add avbove token to join worker on worker system)

 

For Leave swarm

Open terminal on worker1 system and following command for leave

 

#docker swarm  leave   –force

 

Now go to manager system and check node list

#docker   node   ls

For Free Demo classes Call: 7798058777

Registration Link: Click Here!

Step5: Verify Swarm node status

#docker   node   ls

For show details

 

#docker node  –help

#docker node  inspect  manager1

#docker node  inspect  worker1

 

For promote worker as manager

#docker  node promote  worker1

#docker  node  ls

 

For demote  

#docker  node  demote  worker1

#docker   node   ls

Step6: Manage docker swarm service

Replicated service

Replicated service allow us to specify number of services run on worker, we can run number of services on specific worker also.

Global service

Global services are used to run number of services globally on all workers, means if we want to run minimum one service on every node that time global service very useful.

For show service help

#docker  service  –help

For create replicas

#docker  service  create  –replicas  4  –name   web1  nginx

#docker  service  ls

#docker  service  ps  web1

 

For scale up 

#docker  service  –help

#docker  service  scale  web1=7

#docker  service  ps  web1

 

now go to worker1 and remove the running container

#docker  ls

#docker  rm -f 20 50

 

now go to manager and check

#docker service ls

 

Also try from manager system to remove one container it will be start quickly

 

For remove all web1 services

#docker service rm web

#docker service ls

For create new service

#docker service create -d -p 80:80 –name webserver nginx

#docker service ps webserver

#docker service scale webserver=8

 

we can access above services from any node, no need separate ip address

Access it from web browser with help of manager IP

#http:192.168.1.10

 

Step 7: Docker Swarm Visualizer:

We can view docker swarm manager and worker status with visualizer to start visualizer install following docker-swarm-visualizer tool from github

(https://github.com/dockersamples/docker-swarm-visualizer)

To run in a docker swarm:

  #docker service create \

  –name=viz \

  –publish=8080:8080/tcp \

  –constraint=node.role==manager \

  –mount=type=bind,src=/var/run/docker.sock,dst=/var/run/docker.sock \

  dockersamples/visualizer

 

#docker service ls

access visualizer from webbrowser with help of manager IP

#http:192.168.1.10:8080

 

remove again all services of webserver

#docker service rm webserver

#docker service ps webserver

 

Also check with docker visualizer

#http:192.168.1.10:8080

Step 8: Run services in global mode

#docker  service  create  –mode=global  –name   web1  nginx

this mode bydefault run one service on each node

#docker service ps web1

#docker ps

 

or

check visualizer

 

remove again all services of web1

#docker service rm webserver

#docker service ps webserver

Step 9: Now star number of container on specific targeted server

 

Start 3 service (container) on Manager

#docker  service  create  –replicas=3 –constraint=”node.role==manager”  –name   web1  nginx

 

#docker service rm webserver

#docker service ps webserver

 

Start 7 services (container) on worker

#docker  service  create  –replicas=7 –constraint=”node.role==worker”  –name   web1  nginx

For Free Demo classes Call: 7798058777

Registration Link: Click Here!

Step 10: Run number of containers on specific worker with help of label

We can create label on two level:

  1. Node level
  2. Engine level

 

  1. Node level:

First set label to worker1

 

#docker node update  –help | grep label

#docker node update  –label-add=”ssd=true” worker1.example.com

 

#docker  service  create  –replicas=3 –constraint=”node.labels.ssd==true”  –name   web1  nginx

 

check docker swarm visualizer container status

 

  1. Engine level

Now create label worker2

go to worker2 system 

 

#vim /etc/docker/daemon.jeson

{

  “labels”  :  [“name=sevenmentor”]

}

:wq

 

restart system

#systemctl   restart   docker

 

go to manager check label engin level

 

#docker node  inspect  worker2.example.com | less

 

now run service on worker2

#docker  service  create  –replicas=3 –constraint=”engine.labels.name==sevenmentor”  –name   web1 nginx

Compare Kubernetes & Docker Swarm

Kubernets:

  1. Installation process is complicated and time consuming
  2. It can work with almost all containers types like Rocket, Docker, ContainerD etc
  3. GUI version available
  4. Only shared with containers in same POD
  5. Process scheduling to maintain services while updating
  6. Support vertical and horizontal autoscaling
  7. Inbuilt tool present for monitoring and log

For Free Demo classes Call: 7798058777

Registration Link: Click Here!

Docker Swarm:

  1. Installation process is fast and easy.
  2. It can work with only docker container
  3. GUI version not available
  4. Can be shared with any other container.
  5. Progressive updates of services health monitoring throughout the update.
  6. Not support Auto scaling
  7. Used 3rd party tools like slunk

Apache Marathon also competitor of kubernetes and Docker Swarm.

 

Author:-

Abhijit Dahatonde

Call the Trainer and Book your free demo Class  Call now!!!
| SevenMentor Pvt Ltd.

© Copyright 2021 | Sevenmentor Pvt Ltd.

Submit Comment

Your email address will not be published.

*
*