I'm using dns names for my backend servers in my hsproxy.cfg like
backend s0
server server0 server0.x.y.local:8080
backend s1
server server1 server1.x.y.local:8080
The name resolution works fine after startup. But as soon as the ipadress of a backendserver changes, requests to haproxy take a long time (like 25 seconds) and then respond with 503 (reason: SC). It doesn't update or reresolve the dns names. But a curl
on that machine works fine so the operating system updates the ip adress for those dns entries correctly. So it looks like haproxy is caching the ip adress on startup and never changes them.
I'm using haproxy as a pod inside of a kubernetes cluster (not sure if that matters).
From what I read in the offical docs, the libc option should use the operating systems resolve? I have tried putting init-addr libc
but it didn't help, haproxy still responds with long running 503 forever while on the machine, dns resolves perfectly.
I have also seen that there are some fine tunings possible when using a resolver
entry, where you can configure refresh times etc. Is this possible without hardcode nameservers in haproxy.cfg and just use the ones from the operating system?
In this presentation, Julien Pivotto explains how Inuits uses HAProxy in an unconventional way: as a forward proxy to route outgoing traffic. This unique use case has uncovered a trove of useful features within HAProxy.
HAProxy (short for High Availability Proxy) is a software-based TCP/HTTP load balancer. It sends client requests to multiple servers to evenly distribute incoming traffic. By default, HAProxy uses port number 80.
The frontend is the node by which HAProxy listens for connections. Backend nodes are those by which HAProxy can forward requests. A third node type, the stats node, can be used to monitor the load balancer and the other two nodes.
An HAProxy load balancer lets you specify different load balancing modes, depending on the type of application you're serving. Its round-robin mode will send requests to your servers in a rotation and works well when requests take a small and predictable amount of time to handle, such as HTTP requests.
Seems to be correct that HAProxy does cache the resolved IP unless you tell it otherwise.
As you already found the configuration using a resolver and a custom check interval should do the trick (resolvers dns check inter 1000
and hold valid
), but you are also right that this requires a resolvers
section as well. Since HAProxy 1.9 you can use parse-resolv-conf
to use the local resolver:
resolvers mydns
parse-resolv-conf
hold valid 10s
backend site-backend
balance leastconn
server site server.example.com:80 resolvers mydns check inter 1000
The HAProxy documentation can help you with further configuration: https://cbonte.github.io/haproxy-dconv/1.9/configuration.html#5.3.2-parse-resolv-conf
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With