Building Containers stops HAProxy to redirect correctly

Hi!!! :smiley:

It’s the first time writing onto this site.

I have an Openshift istance, and 2 namespaces:

First-layer
Second-layer

the “default” namespace is occupied by HAProxy.

I have configured HAProxy to balance and backup these two Flask Images i deployed over the first and second layer namespaces.

haproxy config file:


global
log stdout format raw local0
maxconn 1024

defaults
log global
timeout client 20s
timeout connect 20s
timeout server 10s

frontend fe_main
bind *:3000
default_backend be_main

backend be_main
server web1 flaskapp-flaskapp-chart.first-layer:8000 check resolvers dnsresolvers
server web2 flaskapp-flaskapp-chart.second-layer:8000 check backup resolvers dnsresolvers

resolvers dnsresolvers
nameserver dns1 dns-default.openshift-dns:53
nameserver dns2 10.217.4.10:53
resolve_retries 3
timeout retry 1s
hold nx 10s
hold valid 10s
resolve_retries 3
timeout resolve 1s
hold other 10s
hold refused 5s

This actually works very good with my structure!
But when i try to destroy and rebuild my pods HAProxy can’t take me to the Flask Application anymore…

I need to restart HAProxy pod and everything goes well. :slight_smile:

Is there something i forgot to use in the config file?
How can i make it find the new pod without having to restart the HAProxy Service?

Thanks!!! :smiley:

The likely cause is the server names. flaskapp-flaskapp-chart.first-layer only works at startup, because the system resolver appends the search domains from /etc/resolv.conf. Your resolvers section re-resolves at runtime, and HAProxy’s built-in resolver doesn’t use search domains. It queries the literal short name, gets NXDOMAIN, and never picks up the new IP after you rebuild. That’s why a restart fixes it. You can also go fully dynamic and skip startup resolution entirely with init-addr none on the server or default-server lines:

    default-server init-addr none

The servers start in maintenance and come up as soon as the resolvers section gets an answer, so the same resolver handles both startup and rebuilds.

Note: if you want to retain libc startup resolution, only if DNS fails haproxy will also start and use dynamic resolution: init-addr libc,none