Customizing haproxy backends for a service loadbalancer

Hi All,

I’m trying to create a redis HA cluster with Rancher, I’m almost done but I can’t understand how to customize my haproxy’s config with the rancher loadbalancer service.

I need to enable a public access with a custom haproxy backend.
Here is my backend added inside “Custom haproxy.cfg” in the UI

backend redis_master
option tcp-check
tcp-check connect
tcp-check send PING\r\n
tcp-check expect string +PONG
tcp-check send info\ replication\r\n
tcp-check expect string role:master
tcp-check send QUIT\r\n
tcp-check expect string +OK
server … IP:PORT check inter 1s

==> the bold text is generated automaticaly by rancher and I don’t know how to add the Italic text.

Any ideas ?

Here is my full rancher-compose.yml :slight_smile:

version: '2'
services:
  redis-master:
    scale: 1
    start_on_create: true
  redis-lb:
    start_on_create: true
    lb_config:
      certs: []
      config: "backend redis_master\n\toption tcp-check\n\ttcp-check connect\n\ttcp-check\
        \ send PING\\r\\n\n\ttcp-check expect string +PONG\n\ttcp-check send info\\\
        \ replication\\r\\n\n\ttcp-check expect string role:master\n\ttcp-check send\
        \ QUIT\\r\\n\n\ttcp-check expect string +OK\n        default-server inter\
        \ 1s\n\nbackend redis_slave\n    option tcp-check\n    default-server inter\
        \ 1s\n\nbackend stats\n  mode http\n  stats enable\n  stats hide-version\n\
        \  stats show-node\n  stats auth admin:password\n  stats uri /haproxy-status"
      port_rules:
      - backend_name: redis_master
        priority: 3
        protocol: tcp
        service: redis-cluster
        source_port: 6377
        target_port: 6379
      - backend_name: redis_slave
        priority: 4
        protocol: tcp
        service: redis-cluster
        source_port: 6378
        target_port: 6379
    health_check:
      healthy_threshold: 2
      response_timeout: 2000
      port: 42
      unhealthy_threshold: 3
      interval: 2000
  redis-slaves:
    start_on_create: true
  redis-cluster:
    start_on_create: true

IIRC, you need to do something like this in your docker-compose file:

  redis-lb:
    ports: 6377:6377
    ports: 6378:6378
    ...

Or for a specific host IP:

  redis-lb:
    ports: 192.168.1.1:6377:6377
    ports: 192.168.1.1:6378:6378
    ...

Thanks sjiveson unfortunately that’s not what I meant.

I need to change the haproxy conf generated with the servers IP.

Sorry but I’m struggling to understand what it is you need?

Hi @quentin

you could add parameters to your backend servers, adding that to your custom config

backend mystack_foo
    server $IP <server parameters>

http://docs.rancher.com/rancher/v1.5/en/cattle/adding-load-balancers/#custom-configuration

In your case, it should be enough adding this custom configuration…

backend redis_master
option tcp-check
tcp-check connect
tcp-check send PING\r\n
tcp-check expect string +PONG
tcp-check send info\ replication\r\n
tcp-check expect string role:master
tcp-check send QUIT\r\n
tcp-check expect string +OK
server $IP check inter 1s

Could you try, please?? :slight_smile:

1 Like

That’s exactly what I was looking for! Thanks a lot!!!