Home > database >  Docker constraints until node going down
Docker constraints until node going down

Time:10-08

I'm having 5 Docker nodes in a cluster [swarm]. Let's say I'll constraint NGINX [it is not about nginx, it is just an example] to be deployed only on Docker node 1. Can I create that constraint in such a way that if Docker node 1 goes down the constraint to not be available anymore?

Like, having that constraint only when the node is reacheable, when it isn't, automatically remove the constraint?

CodePudding user response:

Yes, you can use the placement-ref to place a spread stratergy to your node.hostname=your.node1.hostname as document here https://docs.docker.com/engine/reference/commandline/service_create/#specify-service-placement-preferences---placement-pref.

If the nodes in one category (for example, those with node.labels.datacenter=south) can’t handle their fair share of tasks due to constraints or resource limitations, the extra tasks will be assigned to other nodes instead, if possible.

The downside is that when your node 1 is back online, the service won't be update and rebalance until the service has been updated again (manually or the service is down).

Additionally, it's not a good design if your service has to be placed on a special node but it should be designed to be able to work every where so you can balance server load accross all nodes. Regarding, NGINX, it's stateless and you can deploy it to all of your nodes and let the docker routing mess to do the load balancing. If your service is statefull, even that it's re-deploy to a second node, your data will be not available and your total service is interupted too. So my real answer is that your question is possible but not the expectation of how Docker Swarm is designed and may be not good too.

If you have any good reason to stick with your question solution. You can think about a load balancer in front of your NGINX (or others) like another NGINX or HAProxy which will allow you more control to route your requests to a master node and use secondary or more node for backup purpose only and so on. The design will be that you have a stateless Load Balancer deploy in global mode, and your core service is running behind the LB. This design will give you no downtime when your node 1 is down or service is updating or relocating.

  • Related