markcaudill/haproxy-autoscale — Issue #1: multiple backend capabilities
Author: phrozendice
Created: 2012-01-31 19:45:09+00:00
State: open

A very useful add-on to this excellent tool would be the ability to support multiple backends and multiple security groups.

Sample haproxy configuration file:

frontend demo *:5000
default_backend demo

backend demo
mode http
balance roundrobin
option httpchk HEAD /ha.txt HTTP/1.0
server i-6f0bd222 1.1.1.1:80 weight 100 check

fronted demo2 *:5001
default_backend demo2

backend demo2
mode http
balance roundrobin
option httpchk HEAD /ha.txt HTTP/1.0
server i-6f0bd1111 2.2.2.2:80 weight 100 check

In the above example, there are 2 different backends with instances running on two different security groups. making this tool aware of multiple instances on different security groups would allow you to auto-scale multiple backends at the same time using just one load balancer which in my opinion would be of incredible value for a true auto-scaling infrastructure running on ec2.

The suggested functionality would allow for the following:
- Poll one or more security groups for running instances
- Manipulate haproxy configuration template to attach the running instances to the corresponding backends

Example:
/usr/bin/python update-haproxy.py --security-group(s)=''rails-servers,java-servers"

haproxy.tpl:

frontend www *:80
mode http
maxconn 50000
default_backend servers

backend servers
mode http
balance roundrobin
% for instance in instances $SECURITY_GROUP_1:
server ${ instance.id } ${ instance.private_dns_name }
% endfor

frontend java *:8080
mode http
maxconn 50000
default_backend java-servers

backend java-servers
mode http
balance roundrobin
% for instance in instances $SECURITY_GROUP_2:
server ${ instance.id } ${ instance.private_dns_name }
% endfor

Thank you and great job!!!