Score:0

Mapping FQDN to IP and Port number in HAProxy

cn flag

I have HAproxy in front of my K8s cluster. It works perfectly by IP address and port number.

frontend kubernetes-test-frontend
    bind 10.138.1.187:30030
    mode tcp
    option tcplog
    default_backend kubernetes-test-backend

backend kubernetes-test-backend
    mode tcp
    option tcp-check
    balance roundrobin
    server k8master1 10.138.1.181:30030 check
    server k8master2 10.138.1.182:30030 check
    server k8node1 10.138.1.183:30030 check
    server k8node2 10.138.1.184:30030 check
    server k8node3 10.138.1.185:30030 check

Can I have FQDN to replace IP and port number? For example, if I have www.test.com mapping to 10.138.1.187 in my internal DNS. Can I set up HAproxy to map www.test.com/test to node's IP:30030?

Scott avatar
gf flag
You can’t have FQDN map to IP address and port number.  You should be able to have FQDN map to IP address; but FQDN doesn’t map to port number.  Have you tried `www.test.com:30030`? … … … … … … … … … … … … … … … … … P.S.  Your config file excerpt uses port number 30030, but your *question* mentions port number 30090.
Gerard H. Pille avatar
in flag
Doesn't haproxy have an other mode than TCP?
ITnewbie avatar
cn flag
@Scott Sorry for the typo:)
Mikael H avatar
br flag
@Gerard H. Pille, HAProxy can work in http mode or in tcp mode, and HAProxy can use DNS to lookup server names, but you still need to define the listening port. https://www.haproxy.com/documentation/hapee/latest/configuration/config-sections/backend/
Score:1
br flag

You can switch from using an IP address to using DNS - but read the documentation for your version of HAProxy to understand the potential trade-offs.

If you switch to DNS lookups for your backend servers you will still need to define their listening port in your backend configuration.

ITnewbie avatar
cn flag
Thank you so much! Just like you mentioned, I solved the problem by using http mode and ACL in the HAProxy configuration
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.