TritonDataCenter / sdc-docker

Docker Engine for Triton
Mozilla Public License 2.0
182 stars 49 forks source link

Not respecting Affinity Rules during Docker-Compose scale #112

Open Smithx10 opened 7 years ago

Smithx10 commented 7 years ago

I've discovered if you create an affinity rule and run docker-compose scale consul=3 all 3 instances start on the same node.

(docker) [root@ws jenkins]# docker-compose scale consul=3
Creating and starting jenkins_consul_1 ... done
Creating and starting jenkins_consul_2 ... done
Creating and starting jenkins_consul_3 ... done
(docker) [root@ws jenkins]# triton insts -H -o name,compute_node | sort | uniq -c | sort | grep jenkins_consul
      1 jenkins_consul_1  a92fa576-c97b-0010-a443-c4544472c443
      1 jenkins_consul_2  a92fa576-c97b-0010-a443-c4544472c443
      1 jenkins_consul_3  a92fa576-c97b-0010-a443-c4544472c443

If I run docker-compose scale consul=1 && docker-compose scale consul=2 && docker-compose scale consul=3 they honor the affinity rules.

(docker) [root@ws jenkins]# docker-compose scale consul=1 && docker-compose scale consul=2 && docker-compose scale consul=3
Creating and starting jenkins_consul_1 ... done
Creating and starting jenkins_consul_2 ... done
Creating and starting jenkins_consul_3 ... done
(docker) [root@ws jenkins]# triton insts -H -o name,compute_node | sort | uniq -c | sort | grep jenkins_consul
      1 jenkins_consul_1  a92fa576-c97b-0010-a443-c4544472c443
      1 jenkins_consul_2  0a416e76-c97b-0010-bdb3-c4544472c3fc
      1 jenkins_consul_3  be233e0c-c67b-0010-82d4-c4544464394f

Docker-Compose.yml:

consul:
    image: autopilotpattern/consul:latest
    restart: always
    mem_limit: 128m
    ports:
      - 8500
    dns:
      - 127.0.0.1
    labels:
      - triton.cns.services=jenkins-consul
      - com.example.type=jenkins-consul
      - com.docker.swarm.affinities=["com.example.type!=jenkins-consul"]
    command: >
      /usr/local/bin/containerpilot
      /bin/consul agent -server
        -bootstrap-expect 3
        -config-dir=/etc/consul
        -ui-dir /ui
Smithx10 commented 7 years ago

After reading through ./lib/backends/sdc/affinity.js, I think we are only checking what is currently running and handing it off to DAPI. This explains why when submitted at the same time the services are landing on the same computenode.

papertigers commented 7 years ago

Hey, you likely want:

com.docker.swarm.affinities=["com.example.type!=jenkins-consul*"]

In your example you are trying to match "jenkins-consul" exactly.

Check out https://apidocs.joyent.com/docker/features/placement

Edit: Didn't notice this was a label filter and not container. Let me gather some more data.

papertigers commented 7 years ago

Filed internally as https://smartos.org/bugview/DOCKER-1039