Docker
Orchestration

Orchestration

Problems

How do we automate container lifecycle?

How can we easily scale out/in/up/down?

How can we ensure our containers are recreated if they fail?

How can we replace container without downtime (blue/green deploy)?

How can we create cross-node virtual networks?

How can we ensure only trusted servers run our containers?

How can we store secrets, keys, passwords and get them to the right container (and only that container)?

Answer : Swarm Mode: Built-in Orchestration


Swarm services

to practice this go “play-with-docker” web which will give you VM with install docker

# initialize the swarm mode in current host (as swarm manager) generate a join token
# for other machines to join as worker nodes.
docker swarm init
# paste join-token key to another vm
 
docker node ls
 
docker node update --help
docker node update --role manager node2 # it will update node2 worker to manager
 
docker swarm join-token manager # to generate join token for other vm join as manager.
#creates a Docker service with three replicas of an Alpine container, each pinging the IP adres 8.8.8.8.
docker service create --replicas 3 alpine ping 8.8.8.8
 
docker node ps
 
docker node ps #<any other node name>
 
docker service ps <service name>
 

Network overlay

Swarm by default behavior is to use the "bridge" network driver (LANs). Network overlay : It provides a virtual network overlay that spans the entire swarm cluster, allowing containers to communicate as if they were on the same network, regardless of their physical location.

Swarm lifecycle

The lifecycle of a Swarm cluster involves these key stages:

  1. Initialization: Initialize the cluster by running docker swarm init on the manager node.
  2. Joining Nodes: Other machines join the cluster as worker nodes using docker swarm join.
  3. Service Deployment: Deploy services using Docker Compose or docker service create.
  4. Scaling: Scale services up or down with docker service scale.
  5. Rolling Updates: Apply updates gradually with controlled rolling updates using docker service update.
  6. Monitoring and Health Checking: Monitor services and containers with commands like docker service ps and docker service inspect.
  7. Scaling Down and Removal: Scale down services or remove them with docker service scale or docker service rm.
  8. Cluster Management: Manage the cluster by adding/removing nodes, updating settings, and configuring load balancing.

Note: Swarm has reached its end-of-life, and Kubernetes is now the preferred container orchestration platform.