Open dottgonzo opened 7 years ago
I have been looking into this for quite some time. But I cant figure out a way to do it. With mode global more than one instance would start at a time. So its pure luck, that we dont run into a race condition where more than one instance thinks its the first one and will go into bootstrap mode. But since all tasks in a swarm are completely identical in configuration, there is no way of "hard coding" the bootstrap mode into just one of them. Another idea was to start a single bootstrap service. And then point the "normal" cluster members to this service for bootstrapping. But this will result in a condition, were at failure a restarted task will look for this bootstrapping instance again, since by configuration its the only node it is aware of. Afaik Swarm mode does its scheduling by trying to spread out workload evenly on the available nodes. At the beginning it tries to put one task of a service on each node. Which would result in an evenly spread out cluster over all nodes. Using constraint flags doesnt help either, since swarm just supports labels tied to nodes and not to services. When using Rancher for orchestrating a Docker Cluster, you could define constraints like: dont put on same node as container X or service Y. Docker Swarm does not offer such constraints yet.
I'm happy to say that my stupid workaround, with mode global, works like expected. Maybe my bad English not helps, i will try to repeat what i can do to ensure to be able to use the global mode:
0) you have your swarm running
1) on only 1 node let's add a label like mariadb=true (for this example)
1) let's add the constraint for the service, for example on the deploy section of docker compose :
mode: global
placement:
constraints:
- node.labels.mariadb == true
2) now i deploy the stack and see that it starts only on the node labeled with mariadb=true, so this will became the master node
3) after the master node start, we can add to the other nodes we want to use, the label mariadb=true, and the other instances will starts from that nodes, and they will join on cluster
I am happy that you found a pretty fine solution for this problem. Will keep it in mind if I need to do such a setup one time.
Thanks, Chris
Hi, after some days spent on docker swarm, i'm happy to not have persistent volumes and to see that with many replicas all works good. There is another issue that could cause loosing data on cluster. If i need to boot first 1 replica, and then scale, i can't set global mode in docker swarm (because it start all the replicas contemporary), and with the replicated mode is possible that all the replicas are on the same node, so shutting down the node will delete everything. The only one solution (not tested), is to enable global mode, but costrain the service to run on node with certain label and initially set it only on one node, and then adding that label to more nodes. The best is to be able to start all the replicas together. Is possible to fix this issue?