Docker Swarm Mode Orchestration

14
D CKER SWARM MODE ORCHESTRATION ALİCAN AKKUŞ software developer@iyzico @alican_akkus /aakkus alicanakkus.github.io - alicanakkus.com

Transcript of Docker Swarm Mode Orchestration

Page 1: Docker Swarm Mode Orchestration

D CKERSWARM MODE ORCHESTRATIONALİCAN AKKUŞsoftware developer@iyzico @alican_akkus /aakkus alicanakkus.github.io - alicanakkus.com

Page 2: Docker Swarm Mode Orchestration

DOCKER SWARM MODE

What will we be doing today?‣ Clustering and container scheduling

‣ Understandable Distributed Consensus

‣ Build a swarm cluster

‣ One or more node will be manager

‣ Two or more node will be worker

‣ A sample app that uses a Java Spring Boot backend connected to a database to display a fictitious art shop with a React front-end.

‣ Scale the number of containers in the swarm.

2

Page 3: Docker Swarm Mode Orchestration

DOCKER SWARM MODE

Clustering and Container scheduling‣ Orchestration is a broad term that refers to container scheduling, cluster management, and possibly the

provisioning of additional hosts.

‣ In this environment, "scheduling" refers to the ability for an administrator to load a service file onto a host system that establishes how to run a specific container. While scheduling refers to the specific act of loading the service definition, in a more general sense, schedulers are responsible for hooking into a host's init system to manage services in whatever capacity needed.

‣ Cluster management is the process of controlling a group of hosts. This can involve adding and removing hosts from a cluster, getting information about the current state of hosts and containers, and starting and stopping processes. Cluster management is closely tied to scheduling because the scheduler must have access to each host in the cluster in order to schedule services. For this reason, the same tool is often used for both purposes.

3

Page 4: Docker Swarm Mode Orchestration

DOCKER SWARM MODE

Swarm Mode Features‣ The cluster management and orchestration features embedded in the Docker Engine.

‣ You enable swarm mode for an engine by either initializing a swarm or joining an existing swarm.

‣ Docker provides isolation but Swarm mode provides scalability.

‣ With a single engine, applications can be scaled out faster and more effectively.

‣ Swarm can scale up to 50,000 containers and 1,000 nodes with no effect on performance as new containers are added to the cluster.

4

Page 5: Docker Swarm Mode Orchestration

DOCKER SWARM MODE

Swarm Mode Features‣ Declarative service model ;

Docker Engine uses a declarative approach to let you define the desired state of the various services in your application stack. For example, you might describe an application comprised of a web front end service with message queueing services and a database backend.

‣ Scaling ; For each service, you can declare the number of tasks you want to run. When you scale up or down, the swarm manager automatically adapts by adding or removing tasks to maintain the desired state.

‣ Desired state reconciliation ; The swarm manager node constantly monitors the cluster state and reconciles any differences between the actual state and your expressed desired state. For example, if you set up a service to run 10 replicas of a container, and a worker machine hosting two of those replicas crashes, the manager will create two new replicas to replace the replicas that crashed. The swarm manager assigns the new replicas to workers that are running and available.

5

Page 6: Docker Swarm Mode Orchestration

DOCKER SWARM MODE

Swarm Mode Features‣ Multi-host networking ;

You can specify an overlay network for your services. The swarm manager automatically assigns addresses to the containers on the overlay network when it initializes or updates the application.

‣ Load balancing ; You can expose the ports for services to an external load balancer. Internally, the swarm lets you specify how to distribute service containers between nodes.

‣ Secure by default ; Each node in the swarm enforces TLS mutual authentication and encryption to secure communications between itself and all other nodes. You have the option to use self-signed root certificates or certificates from a custom root CA.

6

Page 7: Docker Swarm Mode Orchestration

DOCKER SWARM MODE

Swarm Mode Features‣ Rolling updates ;

At rollout time you can apply service updates to nodes incrementally. The swarm manager lets you control the delay between service deployment to different sets of nodes. If anything goes wrong, you can roll-back a task to a previous version of the service.

‣ Service discovery ;  Swarm manager nodes assign each service in the swarm a unique DNS name and load balances running containers. You can query every container running in the swarm through a DNS server embedded in the swarm.

7

Page 8: Docker Swarm Mode Orchestration

DOCKER SWARM MODE

Distributed Consensus - RAFT‣ Consensus is a fundamental problem in fault-tolerant distributed systems. Consensus involves multiple servers agreeing on values.

‣ Raft is a consensus algorithm that is designed to be easy to understand. It's equivalent to Paxos in fault-tolerance and performance. 

‣ A node can be in 1 of 3 states:‣ the Follower state‣ the Candidate state‣ or the Leader state

‣ All our nodes start in the follower state. If followers don't hear from a leader then they can become a candidate.

‣ Once they reach a decision on a value, that decision is final.

‣ Raft tolerates up to (N-1)/2 failures and requires a majority or quorum of (N/2)+1 members to agree on values proposed to the cluster. 

‣ For example; a cluster of 5 servers can continue to operate even if 2 servers fail. If more servers fail, they stop making progress.

8

Page 9: Docker Swarm Mode Orchestration

DOCKER SWARM MODE

Swarm Mode Features9

Page 10: Docker Swarm Mode Orchestration

DOCKER SWARM MODE

Swarm Mode Features10

Page 11: Docker Swarm Mode Orchestration

DOCKER SWARM MODE

Swarm Mode Features11

Page 12: Docker Swarm Mode Orchestration

DOCKER SWARM MODE

Docker Swarm Mode‣ initalize swarm;

docker swarm init

‣ Once you’ve created a swarm with a manager node, you’re ready to add worker nodes. docker swarm join --token SWTKN-1-231 192.168.99.100:2377

‣ you can join to swarm as manage or worker.

‣ run the docker node ls command to see the worker nodes;* Swarm management commands like docker node ls only work on manager nodes.

id hostname status availability manager status

03g1y59jwfg7cf worker2 Ready Active -a9j68exjopxe7w worker1 Ready Active -dxn1zf6l61qsb * manager1 Ready Active Leader

12

Page 13: Docker Swarm Mode Orchestration

DOCKER SWARM MODE

DEMO‣ A sample app that uses a Java Spring Boot backend connected to a database to display a

fictitious art shop with a React front-end.

‣ We’ve 3 swarm nodes(one manager and two worker)

‣ https://github.com/AlicanAkkus/atsea-sample-shop-app

13

Page 14: Docker Swarm Mode Orchestration

DOCKER SWARM MODE

THANKS :)