Programmatically add nodes to a load balancer like Haproxy?

haproxy api
haproxy dynamic backend
http load balancer
open source load balancer
automate haproxy
haproxy dynamic whitelist
haproxy api commands
how to change haproxy configuration

I'm very sure this problem has been solved, but I can't find any information anywhere about it...

How do sysadmins programmatically add a new node to an existing and running load balancer ? Let's say I have a load balancer running and already balancing say my API server between two EC2 instances, and suddenly there's a traffic spike and I need a third node in the load balancer but I'm asleep... It would be wonderful if I had something monitoring probably RAM usage and some key performance indicators that tell me when I should have another node, and even better if it could add a new node to the load balancer alone...

I'm confident that this is possible and even trivial to do with node-http-proxy and distribute, but I'd like to know if this is possible to do with HAproxy and/or Nginx... I know Amazon's elastic load balancing is probably my best bet but I want to do it on my own (I want to spawn instances from rackspace, EC2, Joyent and probably others as it's convenient).

Once again, spawning a node is easy, I'd like to know how to add it to haproxy.cfg or something similar with Nginx without having to reload the whole proxy, and doing that programatically. Bash scripting is my best bet for this but it still does have to reload the whole proxy which is bad because it loses connections...

You have a few questions in there. For the "add nodes to haproxy without restarting it":

What I do for a similar problem is prepopulate the config file with server names.. e.g. web01, web02 ... web20 even if I only have 5 web servers at the time. Then in my hosts file I map those to the actual ips of the web servers.

To add a new server, you just create an entry for it in the hosts file and it will start passing health checks and get added.

For automated orchestration, it really depends on your environment and you'll probably have to write something custom that fits your needs. There are paid solutions (Scalr comes to mind) to handle orchestration too.

proxy, How do sysadmins programmatically add a new node to an existing and running load balancer ? Let's say I have a load balancer running and already balancing  HAProxy 2.0 introduced layer 7 retries, which provides resilience against unreachable nodes, network latency, slow servers, and HTTP errors. HAProxy powers the uptime of organizations with even the largest traffic demands by giving them the flexibility and confidence to deliver websi

What I do: I have a line in my backend section in haproxy.cfg which says:

# new webservers here

And with a sed script I update haproxy.cfg with something like:

  sed -i -e "/new webservers here/a\    server $ip_address $ip_address:12080 check maxconn 28 weight 100"

And then reload haproxy. Works transparently.

Dynamic Configuration with the HAProxy Runtime API, In this blog post, you'll learn how to dynamically configure HAProxy using the Runtime API. clear counters : clear max statistics counters (add 'all' for all counters) Load Balancer as First Row Defense Against DDoS and clients will be able to move between HAProxy nodes without any side effects. Synopsis HAProxy is a Load-Balancer, this is a fact. It is used to route traffic to servers to primarily ensure applications reliability. Most of the time, the sessions are locally stored in a server. Which means that if you want to split client traffic on multiple servers, you have to ensure each user can be …

HAProxy has a Runtime API that allows you to do just that dynamically.

Please read the official documentation: Dynamic Configuration HAProxy Runtime API

Emulating Active/Passing Application Clustering with HAProxy , Which means that if you want to split client traffic on multiple servers, you have to ensure each user can In very rare cases, the application can't be load-​balanced. we build “active/passive” clusters, where a node can be active at a time. when I put s1 backend back on, all further requests get back to s1. In this blog post, you’ll learn how to dynamically configure HAProxy using the Runtime API. Related blog posts: The Four Essential Sections of an HAProxy Configuration The New HAProxy Data Plane API Over the past 15 years, HAProxy has become well known for its reliability, superior performance, extensible features, and advanced security.

Load Balancing For High Availability With haproxy, Learn how to load balance HTTP and TCP applications with haproxy for solution that allows us to take nodes in and out as needed (often programmatically). One example would be adding logic to the wp-config.php for a  However, this time, when you add an external load balancer, it will only be for the one service and the external load balancer’s configuration can be more static. HAProxy Ingress Controller Best known for reliability and performance, among other features, HAProxy fits all the needs required for an Ingress Controller.

MySQL Load Balancing with HAProxy, However, in other clustering setup like Galera Cluster for MySQL or One possible setup is to install an HAProxy on each web server (or MySQL connections are load-balanced between available DB nodes. This server will receive gradual connections where the weight is dynamically adjusted for 60  The new Data Plane API gives you the ability to dynamically add and configure frontends, backends, and traffic routing logic. You can also use it to manage stick table rules, update logging endpoints, and create SPOE filters. In essence, almost the entire load balancer can be configured using HTTP commands.

How can I remove balanced node from haproxy via command line , I have haproxy running as my load-balancer and from the stats web interface that comes with haproxy, I can put a web server into maintenance mode (and bring it​  Configure Load Balancing. When you configure load balancing using HAProxy, there are two types of nodes which need to be defined: frontend and backend. The frontend is the node by which HAProxy listens for connections. Backend nodes are those by which HAProxy can forward requests.

Comments
  • Have you tried this before? I attempted to do so on HAProxy 1.8 and clearly changing the hosts file modified HAProxies behaviour in no way. I even verified the server was fully accessible from the HAProxy through that change to the hosts file.
  • It's a recommended way to do that? Doesn't seems practical to me. Although, it works.