Scheduling help

I need some help with scheduling rules. I’m trying to get the scheduler to balance 2 instances per host, however so far no love.

Any experts that can chime in?

This doesn’t exist today. I just edited the title in Github to make it slightly more generic.

We also have same need in order to have a proper HA setup of our applications and we haven’t been able to achieve this nicely with current scheduling rules.

Temporary solution

Below I show you how to achieve the “2 instances per host” by creating two identical services that can be scaled independently:

For example, imagine we have a stack “mystack”:

docker-compose.yml:

myapp1:
  image: myorg/myapp:mytag
  label:
    io.rancher.scheduler.affinity:container_label_soft_ne: io.rancher.stack_service.name=mystack/myapp1
    io.rancher.scheduler.affinity:container_label_ne: io.rancher.stack_service.name=mystack/myapp2

myapp2:
  image: myorg/myapp:mytag
  label:
    io.rancher.scheduler.affinity:container_label_soft_ne: io.rancher.stack_service.name=mystack/myapp2
    io.rancher.scheduler.affinity:container_label_ne: io.rancher.stack_service.name=mystack/myapp1

rancher-compose.yml:

myapp1:
  scale: 1
  health_check:
    port: 3000
    interval: 2000
    unhealthy_threshold: 3
    response_timeout: 2000
    healthy_threshold: 2

myapp2:
  scale: 1
  health_check:
    port: 3000
    interval: 2000
    unhealthy_threshold: 3
    response_timeout: 2000
    healthy_threshold: 2

The above will give you the idea. It assures that we have at least 2 containers of the same application (i use same image on app1 and app2) are not running on the same host. Being separated services I can scale them independently and having soft anti-affinity rules will still allow them to be on same host if the other are “too packed”. Changing the scale to 2 will make you do at least 2 containers per host, or at least 3 per host and so on.

It is a kind of dirty-trick since rancher scheduling does not provide this functionality yet.

Related issues

There are two other github issues that are very much related https://github.com/rancher/rancher/issues/2590 and this https://github.com/rancher/rancher/issues/2558

Unfortunately from the labels on github it seems that Rancher is not prioritizing this use cases, they are not part of near release … I really hope they prioritize these issues for letting us do better HA-deployments.