SlideShare uma empresa Scribd logo
1 de 47
Docker Swarm - Basics
SHAHZAD MASUD
SR. TECHNOLOGY SPECIALIST – NETSOL TECHNOLOGIES
17-MAR-2017
Introduction
Roadmap
 Key concepts
 Initializing a cluster of Docker Engines in swarm mode
 Adding nodes to the swarm
 Deploying services to the swarm
 Rolling updates
 Draining Nodes
Traditional Model
Swarm
What ?
• Cluster management and orchestration feature embedded in Docker engine
• Cluster of Docker engines or nodes.
• One manager, and rest workers
Swarm Features
• Cluster Management
• Decentralize design
• Declarative service model
• Scaling
• Desired state reconciliation
• Multi-host network
• Service discovery
• Load balancing
• Secure by default
• Rolling updates
Pre-requisites
Docker installed (CE) (https://www.docker.com/community-edition/)
Docker Knowledge of Application and Services running
(https://docs.docker.com/engine/getstarted-voting-app/)
Docker Engine CLI
◦ Docker version
◦ Docker run hello-world
◦ Docker ps -a
Test Machines
Create three different machines using docker-machine create
1. manager1 (docker-machine create –driver virtualbox manager1)
2. Worker1 (docker-machine create –driver virtualbox worker1)
3. Worker2 (docker-machine create –driver virtualbox worker2)
docker-machine ip manager1 (192.168.99.100)
docker-machine ip worker1 (192.168.99.101)
docker-machine ip worker2 (192.168.99.102)
Additional Network Checks
The following ports must be available. On some systems, these ports are open by default.
• TCP port 2377 for cluster management communications
• TCP and UDP port 7946 for communication among nodes
• UDP port 4789 for overlay network traffic
If you are planning on creating an overlay network with encryption (--opt encrypted), you will
also need to ensure ip protocol 50 (ESP) traffic is allowed.
Create a Swarm (1/4)
Make sure the Docker Engine daemon is started on the host machines.
1. Open a terminal and ssh into the machine where you want to run your manager node. If you
use Docker Machine, you can connect to it via SSH using the following command:
Create a Swarm (2/4)
2. Run the following command to create a new swarm:
Create a Swarm (3/4)
3. Run docker info to view the current state of the swarm:
Create a Swarm (4/4)
4. Run the docker node ls command to view information about nodes:
The * next to the node ID indicates that you’re currently connected on this node.
Docker Engine swarm mode automatically names the node for the machine host name.
Add Nodes to Swarm (1/5)
Make sure the Docker Engine daemon is started on the host machines.
1. Open a terminal and ssh into the machine where you want to add node (worker1). If you use
Docker Machine, you can connect to it via SSH using the following command:
Add Nodes to Swarm (2/5)
2. Run the command produced by the docker swarm init output from the create a swarm step 2
to create a worker node joined to the existing swarm:
Add Nodes to Swarm (3/5)
3. If you don’t have the command available, you can run the following command on a manager
node to retrieve the join command for a worker:
Add Nodes to Swarm (4/5)
4. Repeat Step 1, and Step2 for Worker 2
Add Nodes to Swarm (5/5)
5. Open a terminal and ssh into the machine where the manager node runs and run the docker
node ls command to see the worker nodes:
The MANAGER column identifies the manager nodes in the swarm. The empty status in this
column for worker1 and worker2 identifies them as worker nodes.
Swarm management commands like Docker node ls only work on manager nodes.
Deploy a service to Swarm
1. Open a terminal and ssh into the machine where you run your manager node. For example,
use a machine named manager1. (i.e. docker-machine env manager1)
2. Run the following command:
3. Run Docker service ls to see the list of running services:
Inspect the service on the Swarm (1/2)
1. If you haven’t already, open a terminal and ssh into the machine where you run your
manager node. For example, use a machine named manager1.
2. Run docker service inspect --pretty <SERVICE-ID> to display the details about a service in an
easily readable
Inspect the service on the Swarm (2/2)
3. Run docker service ps helloworld to see which nodes are running the service:
4. Run docker ps on the node where the task is running to see details about the container for
the task.
Scale the service in the Swarm (1/2)
1. If you haven’t already, open a terminal and ssh into the machine where you run your
manager node. For example, the tutorial uses a machine named manager1.
2. Run the following command to change the desired scale of the service running in the swarm:
3. Run docker service ps helloworld to see the updated task list:
Scale the service in the Swarm (2/2)
4. Run docker ps to see the containers running on the node where you’re connected.
Delete service running on swarm (1/2)
1. If you haven’t already, open a terminal and ssh into the machine where you run your
manager node. For example, use a machine named manager1.
2. Run docker service rm helloworld to remove the helloworld service.
3. Run docker service inspect <SERVICE-ID> to verify that the swarm manager removed the
service. The CLI returns a message that the service is not found:
Delete service running on Swarm (2/2)
4. Even though the service no longer exists, the task containers take a few seconds to clean up.
You can use docker ps to verify when they are gone.
Rolling Update (1/6)
1. If you haven’t already, open a terminal and ssh into the machine where you run your
manager node. For example, use a machine named manager1.
2. Deploy Redis 3.0.6 to the swarm and configure the swarm with a 10 second update delay:
Rolling Update (2/6)
3. Inspect the redis service:
Rolling Update (3/6)
4. Now you can update the container image for redis. The swarm manager applies the update
to nodes :
The scheduler applies rolling updates as follows by default:
• Stop the first task.
• Schedule update for the stopped task.
• Start the container for the updated task.
• If the update to a task returns RUNNING, wait for the specified delay period then start the next task.
• If, at any time during the update, a task returns FAILED, pause the update.
Rolling Update (4/6)
5. Run docker service inspect --pretty redis to see the new image in the desired state:
Rolling Update (5/6)
6. The output of service inspect shows if your update paused due to failure:
7. To restart a paused update run docker service update <SERVICE-ID>. For example:
Rolling Update (6/6)
8. Run docker service ps <SERVICE-ID> to watch the rolling update:
Drain a Node on the Swarm (1/5)
1. If you haven’t already, open a terminal and ssh into the machine where you run your
manager node. For example, use a machine named manager1.
2. Verify that all your nodes are actively available.
3. Create a radis service with 3 replicas and update delay of 10 seconds
Drain a Node on the Swarm (2/5)
4. Run docker service ps redis to see how the swarm manager assigned the tasks to different
nodes:
In this case the swarm manager distributed one task to each node. You may see the tasks
distributed differently among the nodes in your environment.
5. Run docker node update --availability drain <NODE-ID> to drain a node that had a task
assigned to it:
Drain a Node on the Swarm (3/5)
6. Inspect the node to check its availability:
Drain a Node on the Swarm (4/5)
7. Run docker service ps redis to see how the swarm manager updated the task assignments for
the redis service:
Drain a Node on the Swarm (5/5)
8. Run docker node update --availability active <NODE-ID> to return the drained node to an
active state:
9. Inspect the node to see the updated state
When you set the node back to Active availability, it can receive new tasks:
◦ during a service update to scale up
◦ during a rolling update
◦ when you set another node to Drain availability
◦ when a task fails on another active node
On Failure (Node)
On Failure (Node) - Rescheduling
On Failure (Manager)
Node Failure
On Failure (Manager) – Backup Managers
On Failure (Manager) - Failed Manager
On Failed (Manager) – Swap Manager
Raft Consensus Algorithm for Swap
The implementation of the consensus algorithm in swarm mode means it features the properties
inherent to distributed systems:
1. agreement on values in a fault tolerant system. (Refer to FLP impossibility theorem and the Raft
Consensus Algorithm paper)
2. mutual exclusion through the leader election process
3. cluster membership management
4. globally consistent object sequencing and CAS (compare-and-swap) primitives
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. This means that in a cluster of 5 Managers running Raft, if 3 nodes
are unavailable, the system will not process any more requests to schedule additional tasks. The
existing tasks will keep running but the scheduler will not be able to rebalance tasks to cope with
failures if when the manager set is not healthy.
Upcoming Topics
1. Manage Sensitive data with Dockers Secret
2. Locking Swarm
3. Attaching services to an overlay network
4. Swarm Administration
5. Raft Consensus in Swarm mode
Useful links
1. http://docs.dockers.com
2. http://www.play-with-docker.com
3. https://github.com/boot2docker/boot2docker/
4. http://github.com/docker/swarm
Thank you – Questions
@shahzadmasud
https://www.facebook.com/shahzadmasud
https://www.linkedin.com/in/shahzadmasud/
shahzadmasud@hotmail.com

Mais conteúdo relacionado

Mais procurados

Mais procurados (20)

Docker Basics
Docker BasicsDocker Basics
Docker Basics
 
Docker Networking Overview
Docker Networking OverviewDocker Networking Overview
Docker Networking Overview
 
Kubernetes
KubernetesKubernetes
Kubernetes
 
Docker introduction &amp; benefits
Docker introduction &amp; benefitsDocker introduction &amp; benefits
Docker introduction &amp; benefits
 
Docker introduction
Docker introductionDocker introduction
Docker introduction
 
Introduction to Docker - VIT Campus
Introduction to Docker - VIT CampusIntroduction to Docker - VIT Campus
Introduction to Docker - VIT Campus
 
Docker 101 - Nov 2016
Docker 101 - Nov 2016Docker 101 - Nov 2016
Docker 101 - Nov 2016
 
Docker, LinuX Container
Docker, LinuX ContainerDocker, LinuX Container
Docker, LinuX Container
 
Docker introduction
Docker introductionDocker introduction
Docker introduction
 
Docker
DockerDocker
Docker
 
Docker: From Zero to Hero
Docker: From Zero to HeroDocker: From Zero to Hero
Docker: From Zero to Hero
 
Understanding docker networking
Understanding docker networkingUnderstanding docker networking
Understanding docker networking
 
Docker compose
Docker composeDocker compose
Docker compose
 
Docker and the Linux Kernel
Docker and the Linux KernelDocker and the Linux Kernel
Docker and the Linux Kernel
 
Docker and kubernetes
Docker and kubernetesDocker and kubernetes
Docker and kubernetes
 
Docker.pptx
Docker.pptxDocker.pptx
Docker.pptx
 
Docker Introduction
Docker IntroductionDocker Introduction
Docker Introduction
 
Introduction to Docker
Introduction to DockerIntroduction to Docker
Introduction to Docker
 
Présentation Docker
Présentation DockerPrésentation Docker
Présentation Docker
 
Networking in Docker
Networking in DockerNetworking in Docker
Networking in Docker
 

Semelhante a Docker Swarm for Beginner

Docker - A lightweight Virtualization Platform for Developers
Docker - A lightweight Virtualization Platform for DevelopersDocker - A lightweight Virtualization Platform for Developers
Docker - A lightweight Virtualization Platform for Developers
RapidValue
 

Semelhante a Docker Swarm for Beginner (20)

Swarm mode
Swarm modeSwarm mode
Swarm mode
 
Docker
DockerDocker
Docker
 
Docker Swarm Mode Orchestration
Docker Swarm Mode OrchestrationDocker Swarm Mode Orchestration
Docker Swarm Mode Orchestration
 
Container orchestration from theory to practice
Container orchestration from theory to practiceContainer orchestration from theory to practice
Container orchestration from theory to practice
 
Container Orchestration with Docker Swarm and Kubernetes
Container Orchestration with Docker Swarm and KubernetesContainer Orchestration with Docker Swarm and Kubernetes
Container Orchestration with Docker Swarm and Kubernetes
 
Docker Basic to Advance
Docker Basic to AdvanceDocker Basic to Advance
Docker Basic to Advance
 
Academy PRO: Docker. Lecture 3
Academy PRO: Docker. Lecture 3Academy PRO: Docker. Lecture 3
Academy PRO: Docker. Lecture 3
 
How Puppet Enables the Use of Lightweight Virtualized Containers - PuppetConf...
How Puppet Enables the Use of Lightweight Virtualized Containers - PuppetConf...How Puppet Enables the Use of Lightweight Virtualized Containers - PuppetConf...
How Puppet Enables the Use of Lightweight Virtualized Containers - PuppetConf...
 
Orchestrating Linux Containers while tolerating failures
Orchestrating Linux Containers while tolerating failuresOrchestrating Linux Containers while tolerating failures
Orchestrating Linux Containers while tolerating failures
 
Docker 1.12 and swarm mode
Docker 1.12 and swarm modeDocker 1.12 and swarm mode
Docker 1.12 and swarm mode
 
Docker Swarm secrets for creating great FIWARE platforms
Docker Swarm secrets for creating great FIWARE platformsDocker Swarm secrets for creating great FIWARE platforms
Docker Swarm secrets for creating great FIWARE platforms
 
swarmmode-dojo
swarmmode-dojoswarmmode-dojo
swarmmode-dojo
 
Docker Workshop - Orchestrating Docker Containers
Docker Workshop - Orchestrating Docker ContainersDocker Workshop - Orchestrating Docker Containers
Docker Workshop - Orchestrating Docker Containers
 
Docker-machine
Docker-machineDocker-machine
Docker-machine
 
Docker Networking & Swarm Mode Introduction
Docker Networking & Swarm Mode IntroductionDocker Networking & Swarm Mode Introduction
Docker Networking & Swarm Mode Introduction
 
Online Meetup: What's new in docker 1.13.0
Online Meetup: What's new in docker 1.13.0 Online Meetup: What's new in docker 1.13.0
Online Meetup: What's new in docker 1.13.0
 
Docker - A lightweight Virtualization Platform for Developers
Docker - A lightweight Virtualization Platform for DevelopersDocker - A lightweight Virtualization Platform for Developers
Docker - A lightweight Virtualization Platform for Developers
 
Docker Swarm scheduling in 1.12
Docker Swarm scheduling in 1.12Docker Swarm scheduling in 1.12
Docker Swarm scheduling in 1.12
 
Gianluca Arbezzano Wordpress: gestione delle installazioni e scalabilità con ...
Gianluca Arbezzano Wordpress: gestione delle installazioni e scalabilità con ...Gianluca Arbezzano Wordpress: gestione delle installazioni e scalabilità con ...
Gianluca Arbezzano Wordpress: gestione delle installazioni e scalabilità con ...
 
Server(less) Swift at SwiftCloudWorkshop 3
Server(less) Swift at SwiftCloudWorkshop 3Server(less) Swift at SwiftCloudWorkshop 3
Server(less) Swift at SwiftCloudWorkshop 3
 

Último

The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 

Último (20)

Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 

Docker Swarm for Beginner

  • 1. Docker Swarm - Basics SHAHZAD MASUD SR. TECHNOLOGY SPECIALIST – NETSOL TECHNOLOGIES 17-MAR-2017
  • 3. Roadmap  Key concepts  Initializing a cluster of Docker Engines in swarm mode  Adding nodes to the swarm  Deploying services to the swarm  Rolling updates  Draining Nodes
  • 6. What ? • Cluster management and orchestration feature embedded in Docker engine • Cluster of Docker engines or nodes. • One manager, and rest workers
  • 7. Swarm Features • Cluster Management • Decentralize design • Declarative service model • Scaling • Desired state reconciliation • Multi-host network • Service discovery • Load balancing • Secure by default • Rolling updates
  • 8. Pre-requisites Docker installed (CE) (https://www.docker.com/community-edition/) Docker Knowledge of Application and Services running (https://docs.docker.com/engine/getstarted-voting-app/) Docker Engine CLI ◦ Docker version ◦ Docker run hello-world ◦ Docker ps -a
  • 9. Test Machines Create three different machines using docker-machine create 1. manager1 (docker-machine create –driver virtualbox manager1) 2. Worker1 (docker-machine create –driver virtualbox worker1) 3. Worker2 (docker-machine create –driver virtualbox worker2) docker-machine ip manager1 (192.168.99.100) docker-machine ip worker1 (192.168.99.101) docker-machine ip worker2 (192.168.99.102)
  • 10. Additional Network Checks The following ports must be available. On some systems, these ports are open by default. • TCP port 2377 for cluster management communications • TCP and UDP port 7946 for communication among nodes • UDP port 4789 for overlay network traffic If you are planning on creating an overlay network with encryption (--opt encrypted), you will also need to ensure ip protocol 50 (ESP) traffic is allowed.
  • 11. Create a Swarm (1/4) Make sure the Docker Engine daemon is started on the host machines. 1. Open a terminal and ssh into the machine where you want to run your manager node. If you use Docker Machine, you can connect to it via SSH using the following command:
  • 12. Create a Swarm (2/4) 2. Run the following command to create a new swarm:
  • 13. Create a Swarm (3/4) 3. Run docker info to view the current state of the swarm:
  • 14. Create a Swarm (4/4) 4. Run the docker node ls command to view information about nodes: The * next to the node ID indicates that you’re currently connected on this node. Docker Engine swarm mode automatically names the node for the machine host name.
  • 15. Add Nodes to Swarm (1/5) Make sure the Docker Engine daemon is started on the host machines. 1. Open a terminal and ssh into the machine where you want to add node (worker1). If you use Docker Machine, you can connect to it via SSH using the following command:
  • 16. Add Nodes to Swarm (2/5) 2. Run the command produced by the docker swarm init output from the create a swarm step 2 to create a worker node joined to the existing swarm:
  • 17. Add Nodes to Swarm (3/5) 3. If you don’t have the command available, you can run the following command on a manager node to retrieve the join command for a worker:
  • 18. Add Nodes to Swarm (4/5) 4. Repeat Step 1, and Step2 for Worker 2
  • 19. Add Nodes to Swarm (5/5) 5. Open a terminal and ssh into the machine where the manager node runs and run the docker node ls command to see the worker nodes: The MANAGER column identifies the manager nodes in the swarm. The empty status in this column for worker1 and worker2 identifies them as worker nodes. Swarm management commands like Docker node ls only work on manager nodes.
  • 20. Deploy a service to Swarm 1. Open a terminal and ssh into the machine where you run your manager node. For example, use a machine named manager1. (i.e. docker-machine env manager1) 2. Run the following command: 3. Run Docker service ls to see the list of running services:
  • 21. Inspect the service on the Swarm (1/2) 1. If you haven’t already, open a terminal and ssh into the machine where you run your manager node. For example, use a machine named manager1. 2. Run docker service inspect --pretty <SERVICE-ID> to display the details about a service in an easily readable
  • 22. Inspect the service on the Swarm (2/2) 3. Run docker service ps helloworld to see which nodes are running the service: 4. Run docker ps on the node where the task is running to see details about the container for the task.
  • 23. Scale the service in the Swarm (1/2) 1. If you haven’t already, open a terminal and ssh into the machine where you run your manager node. For example, the tutorial uses a machine named manager1. 2. Run the following command to change the desired scale of the service running in the swarm: 3. Run docker service ps helloworld to see the updated task list:
  • 24. Scale the service in the Swarm (2/2) 4. Run docker ps to see the containers running on the node where you’re connected.
  • 25. Delete service running on swarm (1/2) 1. If you haven’t already, open a terminal and ssh into the machine where you run your manager node. For example, use a machine named manager1. 2. Run docker service rm helloworld to remove the helloworld service. 3. Run docker service inspect <SERVICE-ID> to verify that the swarm manager removed the service. The CLI returns a message that the service is not found:
  • 26. Delete service running on Swarm (2/2) 4. Even though the service no longer exists, the task containers take a few seconds to clean up. You can use docker ps to verify when they are gone.
  • 27. Rolling Update (1/6) 1. If you haven’t already, open a terminal and ssh into the machine where you run your manager node. For example, use a machine named manager1. 2. Deploy Redis 3.0.6 to the swarm and configure the swarm with a 10 second update delay:
  • 28. Rolling Update (2/6) 3. Inspect the redis service:
  • 29. Rolling Update (3/6) 4. Now you can update the container image for redis. The swarm manager applies the update to nodes : The scheduler applies rolling updates as follows by default: • Stop the first task. • Schedule update for the stopped task. • Start the container for the updated task. • If the update to a task returns RUNNING, wait for the specified delay period then start the next task. • If, at any time during the update, a task returns FAILED, pause the update.
  • 30. Rolling Update (4/6) 5. Run docker service inspect --pretty redis to see the new image in the desired state:
  • 31. Rolling Update (5/6) 6. The output of service inspect shows if your update paused due to failure: 7. To restart a paused update run docker service update <SERVICE-ID>. For example:
  • 32. Rolling Update (6/6) 8. Run docker service ps <SERVICE-ID> to watch the rolling update:
  • 33. Drain a Node on the Swarm (1/5) 1. If you haven’t already, open a terminal and ssh into the machine where you run your manager node. For example, use a machine named manager1. 2. Verify that all your nodes are actively available. 3. Create a radis service with 3 replicas and update delay of 10 seconds
  • 34. Drain a Node on the Swarm (2/5) 4. Run docker service ps redis to see how the swarm manager assigned the tasks to different nodes: In this case the swarm manager distributed one task to each node. You may see the tasks distributed differently among the nodes in your environment. 5. Run docker node update --availability drain <NODE-ID> to drain a node that had a task assigned to it:
  • 35. Drain a Node on the Swarm (3/5) 6. Inspect the node to check its availability:
  • 36. Drain a Node on the Swarm (4/5) 7. Run docker service ps redis to see how the swarm manager updated the task assignments for the redis service:
  • 37. Drain a Node on the Swarm (5/5) 8. Run docker node update --availability active <NODE-ID> to return the drained node to an active state: 9. Inspect the node to see the updated state When you set the node back to Active availability, it can receive new tasks: ◦ during a service update to scale up ◦ during a rolling update ◦ when you set another node to Drain availability ◦ when a task fails on another active node
  • 39. On Failure (Node) - Rescheduling
  • 41. On Failure (Manager) – Backup Managers
  • 42. On Failure (Manager) - Failed Manager
  • 43. On Failed (Manager) – Swap Manager
  • 44. Raft Consensus Algorithm for Swap The implementation of the consensus algorithm in swarm mode means it features the properties inherent to distributed systems: 1. agreement on values in a fault tolerant system. (Refer to FLP impossibility theorem and the Raft Consensus Algorithm paper) 2. mutual exclusion through the leader election process 3. cluster membership management 4. globally consistent object sequencing and CAS (compare-and-swap) primitives 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. This means that in a cluster of 5 Managers running Raft, if 3 nodes are unavailable, the system will not process any more requests to schedule additional tasks. The existing tasks will keep running but the scheduler will not be able to rebalance tasks to cope with failures if when the manager set is not healthy.
  • 45. Upcoming Topics 1. Manage Sensitive data with Dockers Secret 2. Locking Swarm 3. Attaching services to an overlay network 4. Swarm Administration 5. Raft Consensus in Swarm mode
  • 46. Useful links 1. http://docs.dockers.com 2. http://www.play-with-docker.com 3. https://github.com/boot2docker/boot2docker/ 4. http://github.com/docker/swarm
  • 47. Thank you – Questions @shahzadmasud https://www.facebook.com/shahzadmasud https://www.linkedin.com/in/shahzadmasud/ shahzadmasud@hotmail.com

Notas do Editor

  1. The cluster management and orchestration features embedded in the Docker Engine are built using SwarmKit. Docker engines participating in a cluster are running in swarm mode. You enable swarm mode for an engine by either initializing a swarm or joining an existing swarm. A swarm is a cluster of Docker engines, or nodes, where you deploy services. The Docker Engine CLI and API include commands to manage swarm nodes (e.g., add or remove nodes), and deploy and orchestrate services across the swarm. When you run Docker without using swarm mode, you execute container commands. When you run the Docker in swarm mode, you orchestrate services. You can run swarm services and standalone containers on the same Docker instances.
  2. Cluster management integrated with Docker Engine: Use the Docker Engine CLI to create a swarm of Docker Engines where you can deploy application services. You don’t need additional orchestration software to create or manage a swarm. Decentralized design: Instead of handling differentiation between node roles at deployment time, the Docker Engine handles any specialization at runtime. You can deploy both kinds of nodes, managers and workers, using the Docker Engine. This means you can build an entire swarm from a single disk image. 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. 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. 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. 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. 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.
  3. Docker Community Edition (Docker CE) is ideal for developers and small teams looking to get started with Docker and experimenting with container-based apps. Docker CE is available on many platforms, from desktop to cloud to server. Docker CE is available for macOS and Windows and provides a native experience to help you focus on learning Docker. You can build and share containers and automate the development pipeline all from a single environment. Docker CE gives you the option to run stable or edge builds. Stable builds are released once per quarter. Edge builds are released once per month. For more information about Docker CE, see Docker Community Edition.
  4. Note: If you are using Docker for Mac or Docker for Windows to test single-node swarm, simply run docker swarm init with no arguments. There is no need to specify --advertise-addr in this case. To learn more, see the topic on how to Use Docker for Mac or Docker for Windows with Swarm.
  5. The docker service create command creates the service. The --name flag names the service helloworld. The --replicas flag specifies the desired state of 1 running instance. The arguments alpine ping docker.com define the service as an Alpine Linux container that executes the command ping docker.com.
  6. The --update-delay flag configures the time delay between updates to a service task or sets of tasks. You can describe the time T as a combination of the number of seconds Ts, minutes Tm, or hours Th. So 10m30s indicates a 10 minute 30 second delay. By default the scheduler updates 1 task at a time. You can pass the --update-parallelism flag to configure the maximum number of service tasks that the scheduler updates simultaneously. By default, when an update to an individual task returns a state of RUNNING, the scheduler schedules another task to update until all tasks are updated. If, at any time during an update a task returns FAILED, the scheduler pauses the update. You can control the behavior using the --update-failure-action flag for docker service create or docker service update.