Hi,

can someone please help me on this?

I am trying to set up an active-active cluster with swarm and haproxy. I am
struggling with the peers definition as it takes hostname and IP address
into account. With swarm this can be a bit tricky.

I want to use mode host for the ports on the proxy so that I can rout
traffic with DNS and tcp roundrobin to the proxy nodes.

```yml
 proxy:
    image: "saps-proxy:5"
    hostname: '{{.Node.Hostname}}'
    dns: 127.0.0.11
    ports:
      - target: 80
        published: 80
        protocol: tcp
        mode: host
      - target: 443
        published: 443
        protocol: tcp
        mode: host
      - target: 1024
        mode: host
        protocol: tcp
    deploy:
      mode: global
      placement: { constraints: ["node.labels.type == proxy"] }
      resources: { limits: { memory: 2G } }
```

In the haproxy.cfg I am defining a peers section.

```conf
peers layer7-loadbalancer
    bind *:1024
    server hostname1.bloom.com
    server hostname2.bloom.com 10.128.0.2:1024  # (ip of real host)
```

This seems to work for the local peer. But I think it's actually using the
container IP. I can also not really spawn replicas from this.

So I try another syntax. When written like this HAProxy will bind IP:port
from the peer name that is matching the hostname.

```
peers layer7-loadbalancer
    peer hostname1.bloom.com 10.128.0.1:1024  # (ip of real host)
    peer hostname2.bloom.com 10.128.0.2:1024  # (ip of real host)
```

I get an error though.

```
Starting proxy hostname1.bloom.com:
cannot bind socket (Cannot assign requested address) [10.128.0.1:1024]
```

This makes sense because the container IP is actually not the host IP. That
is why this address cannot be bound from inside the container.

At this point, I am not really sure how to solve this.

Regards,
Nico

Reply via email to