Part 6- Docker Swarm Cluster

Loading

# Initialise swarm cluster
sudo docker swarm init –advertise-addr <ip of eth0 or public-ip> 

# To find the token generated for a worker or a manager 
docker swarm join-token worker
docker swarm join-token manager

# To add a worker to this swarm, run the following command:
docker swarm join –token SWMTKN-1-27coght3o3vgoki6qke48fcbh22gvkve4eroot103092o0pqqt-1ns3vv1viq1o5pv6uc9mairum 10.0.0.20:2377

# docker swarm join–token worker

# To display all docker swarm nodes
docker node ls

# Inspecting Manager Node Status 
docker node inspect <managername> –format “{{ .ManagerStatus.Reachability }}”
#Manager
docker node inspect swarm100 –format “{{ .ManagerStatus.Reachability }}”
#Workers
docker node inspect swarm101 –format “{{ .Status.State }}”
docker node inspect swarm102 –format “{{ .Status.State }}”
docker node inspect swarm103 –format “{{ .Status.State }}”

#Inspecting a Node ( Troubleshooting)
docker node inspect swarm01
docker node inspect swarm01 –pretty
docker node inspect swarm01 –pretty | grep -i Add*

# create a swarm  docker service
docker service create –name <servicename> –replicas <numberofreplicas> <image>
docker service create –name webservers –replicas 1 nginx:latest 

#Create a swarm sevice using GLOBAL
docker service create –name grafananodes –mode global grafana/grafana
–mode global ensures the all nodes available in swarm gets a container without specifying number of replicas required 

# create a swarm docker service with port ( If no port is mentioned the container wont be accesible from outisde)
docker service create –name mcd –replicas 5 -p 7001:80 nginx:latest

# create a swarm docker service with a network
docker service create –name myoverlay –network mynetwork –replicas 3 nginx

# To display all services i created or defined 
docker service ls

#Inspecting a Service
docker service inspect demotroubleshoot
docker service inspect demotroubleshoot –pretty
docker node inspect swarm101 –format “{{ .Status.State }}””{{ .Status.Addr }}”

# Verify the Host where service is created:

docker service ps myservice
docker service ps east-webservers 

# To display/locate the running service in a swarm with desired config 
docker service ps east-webservers –filter DESIRED-STATE=running
docker service ps east-webservers –filter DESIRED-STATE=running –filter NODE=swarm101

# 2 Approaches to Scale Servers
#———————————— 

# Scaling Up Operation for multiple services ( Autoscaling)
docker service scale <service name1> <servicename2>
docker service scale webserver1=5 webserver2=2
#or # for single service
docker service scale webserver=2

# or 

# Scaling up operation for a single service 
docker service update –replicas 2 webserver

#Scaling Down Operation
docker service scale webserver=1

#Verify Service Details:
docker service ls
docker service ps webserver

#Remove Services
docker service rm webserver

#Change the Node Availability to Drain ( Maintainence Mode)
docker node update –availability drain swarm03

#Verify Node status
docker node ls

#Change the Node Availability To Active
docker node update –availability active swarm03

# Swarm Password
SWMKEY-1-Ks2bW8Kivk4U32BeMV71W+qYWnpubXfnXVCdhobvHKI

# Create Service with Volume
docker service create –name myservice –mount type=volume,source=myvolume,target=/mypath nginx

(Visited 44 times, 1 visits today)

By C A Thomas

Chinchu A. Thomas is an Infrastructure Analyst specializing in Microsoft Azure, the Microsoft 365 suite, AWS, and Windows infrastructure management products.

Leave a Reply