Download - Introduction to docker swarm
Walid AshrafResearcher , Software Developer, Instructor
about.me/WalidAshraf
INTRODUCTION TO DOCKER SWARM
Docker Swarm - Walid Ashraf
Docker Basic Architecture
Native Client
UCP Third party
Docker Swarm - Walid Ashraf
INTRODUCTION TO DOCKER SWARM
Docker Swarm - Walid Ashraf
Docker Swarm - Walid Ashraf
What is Swarm
Docker Swarm is native clustering for Docker.
• It turns a pool of Docker hosts into a single, virtual Docker host.
Docker Swarm serves the standard Docker API, any tool that already communicates with a Docker daemon can use Swarm to transparently scale to multiple hosts.
Docker Swarm - Walid Ashraf
Docker Swarm - Walid Ashraf
Docker Discovery ServiceA key Value store for configurations
• Consul• Etcd• ZooKeeper
Defaults to a hosted discovery service with Docker Swarm.
The service maintains a list of IPs in your cluster. This page describes the different types of hosted discovery available to you.
Discovery service replacements (Libkv abstraction):
Should be replicated
Docker Swarm - Walid Ashraf
Swarm Manager
It’s the cluster admin or master
• 1 Primary (the Actual Admin)• Multiple Secondary Managers (Transfers to primary)• In case of primary failure (leader election occurs)
All communications with nodes passes through it
Supports HA
Docker Swarm - Walid Ashraf
How this works
Docker Swarm - Walid Ashraf
Filtering:The ability to mask some of the nodes
Constraints
• node to refer to the node by ID or name• storagedriver• executiondriver• kernelversion• operatingsystem
Resources
• Containerslots Number of containers on a host• Port
Containers
• Affinity filters• container name or id• an image on the host• a custom label applied to the container
• Depencecy
Docker Swarm - Walid Ashraf
Scheduling
Random
• Default• Least no of containers• CPU and RAM aware
Spread
• Most no of containers• CPU and RAM aware
Binpack
Docker Swarm - Walid Ashraf
CREATING SWARM INFRASTRUCTURE
Docker Swarm - Walid Ashraf
1 – Create Masterdocker swarm init --advertise-addr <MANAGER-IP>$ docker swarm init --advertise-addr 192.168.99.100docker info
Swarm: activeNodeID: dxn1zf6l61qsb1josjja83ngzIs Manager: trueManagers: 1Nodes: 1
docker node lsID HOSTNAME STATUS AVAILABILITY MANAGER STATUSdxn1zf6l61qsb1josjja83ngz * manager1 Ready Active Leader
Docker Swarm - Walid Ashraf
2 – Add Nodes$ docker swarm join \ --token SWMTKN-1-49nj1cmql0jkz5s954yi3oex3nedyz0fb0xx14ie39trti4wxv-8vxv8rssmk743ojnwacrr2e7c \ 192.168.99.100:2377Docker node ls
ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS03g1y59jwfg7cf99w4lt0f662 worker2 Ready Active9j68exjopxe7wfl6yuxml7a7j worker1 Ready Activedxn1zf6l61qsb1josjja83ngz * manager1 Ready Active Leader
Docker Swarm - Walid Ashraf
DEPLOYING A SERVICE
Docker Swarm - Walid Ashraf
What is a serviceA service is a container in swarm mode.Examples of services might include an HTTP server, a database, or any other type of executable program that you wish to run in a distributed environment.Things to be configured in a service
The port where the swarm will make the service available outside the swarmAn overlay network for the service to connect to other services in the swarmCPU and memory limits and reservationsA rolling update policyThe number of replicas of the image to run in the swarm
Docker Swarm - Walid Ashraf
Docker Swarm - Walid Ashraf
Replicated and global services
Docker Swarm - Walid Ashraf
Creating a service$docker service create --replicas 1 --name helloworld alpine ping docker.com
• ID NAME SCALE IMAGE COMMAND• 9uk4639qpg7n helloworld 1/1 alpine ping docker.com
$ docker service ls• ID: 9uk4639qpg7npwf3fn2aasksr• Name: helloworld• Mode: REPLICATED• Replicas: 1• Placement:• UpdateConfig:• Parallelism: 1• ContainerSpec:• Image: alpine• Args: ping docker.com
$ docker service inspect --pretty helloworld
• ID NAME SERVICE IMAGE LAST STATE DESIRED STATE NODE• 8p1vev3fq5zm0mi8g0as41w35 helloworld.1 helloworld alpine Running 3 minutes Running worker2
$ docker service ps helloworld
Docker Swarm - Walid Ashraf
Scaling a service$ docker service scale helloworld=5$ docker service ps helloworld
ID NAME SERVICE IMAGE LAST STATE DESIRED STATE NODE8p1vev3fq5zm0mi8g0as41w35 helloworld.1 helloworld alpine Running 7 minutes Running worker2c7a7tcdq5s0uk3qr88mf8xco6 helloworld.2 helloworld alpine Running 24 seconds Running worker16crl09vdcalvtfehfh69ogfb1 helloworld.3 helloworld alpine Running 24 seconds Running worker1auky6trawmdlcne8ad8phb0f1 helloworld.4 helloworld alpine Running 24 seconds Accepted manager1ba19kca06l18zujfwxyc5lkyn helloworld.5 helloworld alpine Running 24 seconds Running worker2
Docker Swarm - Walid Ashraf
Delete a service$ docker service rm helloworld
helloworld
High AvailabilitySecurity
OTHER CONSIDERATIONS
Docker Swarm - Walid Ashraf
Thinking about High Availability
Docker Swarm - Walid Ashraf
HA over Multiple clouds
Docker Swarm - Walid Ashraf
Implementing High AvailabilityNote: Default Discovery service needs a key value configuration manager Manager1
swarm manage -H :4000 <tls-config-flags> --replication --advertise 192.168.42.200:4000 consul://192.168.42.10:8500/nodes
Manager 2swarm manage -H :4000 <tls-config-flags> --replication --advertise 192.168.42.201:4000 consul://192.168.42.10:8500/nodes
Docker Swarm - Walid Ashraf
TLS for Docker Swarm
Docker Swarm - Walid Ashraf
Referenceshttps://docs.docker.com/swarm/https://docs.docker.com/engine/swarm/swarm-tutorial
Docker Swarm - Walid Ashraf