Friday, October 4, 2019

Docker Swarm - master workers : Docker Cluster Architecture

Docker Swarm

Docker swarm is one of the crucial components of the Docker ecosystem. Native Docker Clustering with Swarm gives us the ability to do scheduling, high availability, security, and platform scalability.
Kubernetes, fleet, Mesos work similar to achieve the same goal. They get layer abstraction for system resources and allows the interfaces to the cluster manager.

Docker swarm is NOT a plugin it is built-in into docker engine. A basic docker installation can run swarm cluster it does not require any plugin to install.

What is Docker Swarm Orchestration?

The docker swarm is a clustering and scheduling tool for Docker containers. With this docker swarm, DevOps operators and developers can establish and manage a cluster of Docker nodes as a single virtual system

A swarm is a group of nodes that are running on Docker daemon (doccker engine) with Swarm master and worker nodes which will be joined to form a containers cluster to provide HA in production environments.


Docker Swarm features



  • Cluster management: Use the Docker Engine CLI to create a swarm of Docker Engines where you can deploy application services 
  • Declarative service model: Uses a declarative approach to let you define the desired state of the various services in your application stack 
  • Scaling: When you scale up or down, the swarm manager automatically adapts by adding or removing tasks to maintain the desired state
  • Desired state reconciliation: Swarm manager node constantly monitors the cluster state and reconciles any differences between the actual state and your expressed desired state 
  • Service discovery: Swarm manager nodes assign each service in the swarm a unique DNS name and load balances running containers 
  • Rolling updates: At rollout time you can apply service updates to nodes incrementally. If anything goes wrong, you can roll-back a task to a previous version of the service

  • To work with Docker swarm, we need to enable it. To run proper docker swarm better run at least 3 docker clients VM with docker installed already. Make sure that all the VMs should be in the same timezone and also with the same date and time.


    # IN MANAGER NODE docker swarm 'init' subcommand is used for creating a new docker swarm cluster. The node on which 'init' runs by default becomes a manager.
     docker swarm init --advertise-addr=192.168.33.110
    

    docker swarm init command execution
    # Confirm the manager node in the list
     docker node ls
    

    # In the 192.168.33.111 box
     # To add a worker to this swarm, run the following command:
     docker swarm join --token SWMTKN-1-5th0jl9mqq7fthcpabioyinoc1x109z3b6viahdilm2v841rwc-c8c17dj7stkld1zpwkxibt4zl 192.168.33.110:2377
    docker swarm cluster joining commands execution

    Note: If you did not have the manager's output. to get the token for the worker to join as follows:
    docker swarm join-token worker
    

    In the Manager node check the node list after joining the worker it should show 2 nodes information.
     docker node ls
    

    docker Node list to check the swarm cluster

    Note that we cannot run a node that made as 'Manager' cannot join the worker on the same node. Nodes, services, containers, and tasks

    Service deploy in Swarm 



    • Services are really just running “containers in production” 
    • A service only runs one image, but it codifies the way that image runs—what ports it should use, how many replicas of the container should run so the service has the capacity it needs, and so on 
    • Scaling a service changes the number of container instances running that piece of software 

    Service Creation

     Create service across the docker swarm cluster

     docker service create --name webapp1 --replicas=4 --publish 8090:80 nginx
    


    # List of services
     docker service ls
     
    docker service with publish option command execution

    # List of services running
     docker service ps webapp1
    

    You can view the container running Nginx with a default page from any one of the node host IP address:
    Running service in multiple replicas on Swarm cluster nodes

    Scaling service 

    Scale up to 8 tasks
    docker service scale web=8
    

    Global mode service creation
    docker service create --name test-redis --mode global redis
    

    This will run a task of the service on every node in  the Docker Swarm cluster check it with
    docker service ls
    

    Look at the changes in the network after swarm initiated
    docker network ls
    

    # Observed 2 new networks added docker_gwbridge, ingress

    docker swarm - overlay network


     Docker autolock is enabled at two commands: swarm init and swarm update The following is the docker command to enable autolock on an exists
    root@dockerhost:~# docker swarm update --autolock=true
    Swarm updated.
    To unlock a swarm manager after it restarts, run the `docker swarm unlock`
    command and provide the following key:
    
        SWMKEY-1-iWhW+8iF17n1C/2aPKcULTAwpi9pcmEsl2GKHtUwzhU
    
    Please remember to store this key in a password manager, since without it you
    will not be able to restart the manager.
    root@dockerhost:~# vi swarmkey.txt
    

    Default Overlay network

    Remember this, 10.0.0.1/8 is the default address pool used by docker swarm for global scope overlay network

    Previous Post for review:

    GCP Cloud users note: 

    1. On Google Cloud if you are joining the swarm cluster please use the Private IP address of master in 'docker swarm join' command. 
    2. You can take out the node from the swarm cluster using 'docker swarm leave' command on the worker node.
    3. When you try to access the new service port on the GCP open that on the firewall - tcp port for the same.

    References

    No comments:

    Categories

    Kubernetes (24) Docker (20) git (13) Jenkins (12) AWS (7) Jenkins CI (5) Vagrant (5) K8s (4) VirtualBox (4) CentOS7 (3) docker registry (3) docker-ee (3) ucp (3) Jenkins Automation (2) Jenkins Master Slave (2) Jenkins Project (2) containers (2) create deployment (2) docker EE (2) docker private registry (2) dockers (2) dtr (2) kubeadm (2) kubectl (2) kubelet (2) openssl (2) Alert Manager CLI (1) AlertManager (1) Apache Maven (1) Best DevOps interview questions (1) CentOS (1) Container as a Service (1) DevOps Interview Questions (1) Docker 19 CE on Ubuntu 19.04 (1) Docker Tutorial (1) Docker UCP (1) Docker installation on Ubunutu (1) Docker interview questions (1) Docker on PowerShell (1) Docker on Windows (1) Docker version (1) Docker-ee installation on CentOS (1) DockerHub (1) Features of DTR (1) Fedora (1) Freestyle Project (1) Git Install on CentOS (1) Git Install on Oracle Linux (1) Git Install on RHEL (1) Git Source based installation (1) Git line ending setup (1) Git migration (1) Grafana on Windows (1) Install DTR (1) Install Docker on Windows Server (1) Install Maven on CentOS (1) Issues (1) Jenkins CI server on AWS instance (1) Jenkins First Job (1) Jenkins Installation on CentOS7 (1) Jenkins Master (1) Jenkins automatic build (1) Jenkins installation on Ubuntu 18.04 (1) Jenkins integration with GitHub server (1) Jenkins on AWS Ubuntu (1) Kubernetes Cluster provisioning (1) Kubernetes interview questions (1) Kuberntes Installation (1) Maven (1) Maven installation on Unix (1) Operations interview Questions (1) Oracle Linux (1) Personal access tokens on GitHub (1) Problem in Docker (1) Prometheus (1) Prometheus CLI (1) RHEL (1) SCM (1) SCM Poll (1) SRE interview questions (1) Troubleshooting (1) Uninstall Git (1) Uninstall Git on CentOS7 (1) Universal Control Plane (1) Vagrantfile (1) amtool (1) aws IAM Role (1) aws policy (1) caas (1) chef installation (1) create organization on UCP (1) create team on UCP (1) docker CE (1) docker UCP console (1) docker command line (1) docker commands (1) docker community edition (1) docker container (1) docker editions (1) docker enterprise edition (1) docker enterprise edition deep dive (1) docker for windows (1) docker hub (1) docker installation (1) docker node (1) docker releases (1) docker secure registry (1) docker service (1) docker swarm init (1) docker swarm join (1) docker trusted registry (1) elasticBeanStalk (1) global configurations (1) helm installation issue (1) mvn (1) namespaces (1) promtool (1) service creation (1) slack (1)