1

When I give multiple label placement constraints and deploy the stack, the services are not running in either of the mentioned constraints.

Ex:

deploy:
    mode: global
    placement: 
        constraints: 
            - node.labels.type == test  
            - node.labels.type == prod
    restart_policy:
        condition: on-failure

But if I give only one constraint (any one) then it is working in that label node.

I have seen the same here. The difference is there are two kinds of constraints (node type and label) are used. But I used only one kind (label).

Is it allowed to use same kind of constraints. If it is how to use it.

Update

Ex:

deploy:
    mode: global
    placement: 
        constraints: 
            - node.hostname == server1  
            - node.hostname == server2
    restart_policy:
        condition: on-failure

Now this should run the service on both servers. But the service is not at all starting.

Ram Idavalapati
  • 666
  • 1
  • 10
  • 22

1 Answers1

3

What happens with that configuration is that you try to deploy to a server where the label type is BOTH (not either) "test"and "prod". That is not going to work.

If you need these "test" and "prod" labels elsewhere, your option is to create a third label, for example "foo":

docker node update --label-add foo=bar NODE

Then you can use that in your constraints:

constraints:
    - node.labels.foo == bar
Teemu Risikko
  • 1,205
  • 11
  • 16
  • Sorry for not being clear. I will update it to make it simple. – Ram Idavalapati Jul 12 '18 at 08:11
  • 1
    @RamIdavalapati Your example has the same problem. That will not run it on both servers. If you have only those two servers, remove the whole constraints-block. `mode: global` ensures that the container runs on all of your nodes. – Teemu Risikko Jul 12 '18 at 08:43