anil kumar d
anil kumar d

Reputation: 177

Dynamically create Backend section in HAProxy configuration

I have a use case where i need to use HAProxy as a proxy rather than a loadbalancer. So in my case i need many backend sections that need to be updated in the config when proxy is started.

But is there a way , where i can create new backend section dynamically ?

global

log stdout format raw daemon
stats socket [email protected]:9999 level admin
stats socket /var/run/hapee-lb.sock mode 666 level admin
stats timeout 2m

defaults

log global
timeout client 50s
timeout client-fin 50s
timeout connect 5s
timeout server 10s
timeout tunnel 50s

frontend tcp-0_0_0_0-443

bind 135.27.110.163:443
mode tcp
tcp-request inspect-delay 5s
tcp-request content accept if { req_ssl_hello_type 1 }    
use_backend %[req.ssl_sni,regsub(.com,.com443,g),lower,map_dom(/usr/local/etc/sample.map,bk_default)]
default_backend example_com_be

frontend tcp-0_0_0_0-5061

bind 135.27.110.163:5061
mode tcp
tcp-request inspect-delay 5s
tcp-request content accept if { req_ssl_hello_type 1 }
use_backend %[req.ssl_sni,regsub(.com,.com5061,g),lower,map_dom(/usr/local/etc/sample.map,bk_default)]   
default_backend absanity_5061

backend example_com_be

mode tcp
server name1 x.x.x.x:443

backend absanity_5061

mode tcp
server name1 y.y.y.y:5061

AM using Runtime API using Socat for updating maps. But assume i was to insert a new backend section with new server details in config .. how can we achieve that ?

Upvotes: 1

Views: 7657

Answers (1)

mweiss
mweiss

Reputation: 1373

I don't think you can create new backends at runtime with the socket API. This article gives a good overview of what you can modify at runtime: https://www.haproxy.com/blog/dynamic-configuration-haproxy-runtime-api/.

However, you can add new backends without using the socket API by creating a new config with the new backends and reloading HAProxy. This article gives a good overview of how to reload HAProxy without losing connections: https://www.haproxy.com/blog/truly-seamless-reloads-with-haproxy-no-more-hacks/

Upvotes: 1

Related Questions