Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HAProxy to use DNS from operating system?

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?

like image 785
Jens Avatar asked May 07 '20 10:05

Jens


People also ask

Can HAProxy be a forward proxy?

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.

Is HAProxy a Web server?

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.

What is frontend and backend HAProxy?

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.

How does HAProxy load balancing Work?

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.


1 Answers

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

like image 164
Simon Avatar answered Oct 23 '22 08:10

Simon