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?
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