Haproxy high availability configuration?

How to make haproxy highly available? Can I just increase number of replicas and spread them across the nodes? Is this enough?

Whats a replica in the context of haproxy?
Do you mean peers?

peers sync stick tables, that is it. They don’t make your instance HA.

You need to think about how the traffic is reaching a haproxy node during a fault that you want to cover.

Usually on Linux when all nodes are on the same LAN you’d use Keepalived and point your clients to the virtual IP that can move between nodes during a fault.

1 Like

I run haproxy as a load balancer in front of rabbit mq cluster (multiple nodes). We use docker swarm. So, rabbitmq clients reach haproxy via rabbit_loadbalancer DNS that is managed by docker swarm and round robins haproxy replicas

services:
  loadbalancer:
    image: haproxy:3.2
    configs:
      - source: haproxy.cfg
        target: /usr/local/etc/haproxy/haproxy.cfg
    deploy:
      replicas: 2
      resources:
        limits:
          cpus: "1"
          memory: "2147483648"
        reservations:
          cpus: "0.1"
          memory: "134217728"
    healthcheck:
      test:
        - CMD-SHELL
        - bash -c 'echo "" > /dev/tcp/127.0.0.1/32087 || exit 1'
    networks:
      rabbit: null

I believe this shall do the job. However, I wonder how to properly gather statistics (I presume haproxy container are unaware of their peers).

Haproxy is unaware that it is instantiated by docker swarm, how docker swarm is configured and what your intention with this configuration would be. Only docker swarm knows that.

You need to collects statistics individually.