Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deploying Docker Swarm mode services across multiple failure domains

I am new to docker swarm mode (and I specifically am talking about swarm mode in docker v1.12, and I do not mean the older non integrated 'docker swarm').

I am attempting to evaluate its suitability to build a large distributed containerised platform for a new software project (I'm comparing to similar technologies such as mesosphere, kubernetes et al).

My understanding of the older non-integrated docker swarm (not swarm mode) is that you could target nodes to deploy to multiple failure domains by using filters. Is there an equivalent in Docker Swarm mode?

For example in a test environment, I have 6 VM's - all running docker.

I start up VM 1 and 2 and call that my failure domain1
I start up VM 3 and 4 and call that my failure domain2
I start up VM 5 and 6 and call that my failure domain3

All failure domains consist of one swarm manager and one swarm worker. In effect, I have 2 nodes per domain that can host service containers.

I tell docker to create a new service, and run 3 containers based upon an image containing a simple web service. Docker does it's thing and spins up 3 containers and my service is running; I can access my load balanced web service without any problems. Hurrah!

However, I'd like to specifically tell docker to distribute my 3 containers across domain1, domain2 and domain3.

How can I do this? (also - am I posting on the correct site - should this be on one of the other stackexchange sites?)

like image 470
Jay Avatar asked Oct 19 '22 02:10

Jay


1 Answers

You can continue to use engine labels as you have before. Or with the new swarm you can defined node labels on the swarm nodes. Then, with the new docker swarm, you would define a constraint on your service and create 3 separate services, each constrained to run in one of your failure domains.

For node labels, you'd use docker node update --label-add az=1 vm1 which would add label az1 to your vm1 node. Repeat this process for your other AZ's (availability zone is the term I tend to use) and VM's.

Now when scheduling your job, you add a constraint like

docker service create --constraint node.labels.az==1 \
  --name AppAZ1 yourimage

for a node label or for an engine label:

docker service create --constraint engine.labels.az==1 \
  --name AppAZ1 yourimage

repeating this for each of your AZ's.

Unfortunately I can't think of a way to force a spread across each of the AZ's automatically when you use something like a --replicas 3 that includes failover to the second node in each vm cluster. However, if you selecte a single VM per cluster for each task, you could label each of them my the same label (e.g. --label-add vm=a, and then do a --mode global --constraint node.label.vm==a to run one service on each of your A nodes.

like image 134
BMitch Avatar answered Oct 23 '22 10:10

BMitch