HAProxy Container Setup

So I have read the documentation but honestly without seeing an actual example of a config I am really having a hard time getting my head wrapped around this.

I have the following setup:

I have 1x physical baremetal machine that has Ubuntu running with HAProxy installed as an application directly on the operating system and then Docker that is running multiple containers.

Before anyone freaks out, this is just running as a temporary/example and is NOT production.

But I am not sure how to write out the HAProxy config file. I have it currently as:

https://hastebin.com/edibifetif.cfg

I have the following domains that are going to be pointing to my public IP:

Can someone please assist me with showing the config file should be written. I am looking at this tutorial:

But I am not sure if the containers would be properly like this:

https://hastebin.com/danuparoqi.cfg

Can someone please help out?

Hi,

as I can see your global/default configuration is default. Thats a config to start with… but your config has some mistakes.

It looks like you try to load-balance between to different application services! I think you must separate this. I attached a simple example for you. In the example there where 2 frontends (one for your services ans one for the stats) and multiple backends for your services eg. chat cloud etc.

   frontend http_FE
   bind *:80
  
   acl is_chat hdr(host) -i chat.temp.com
   acl is_cloud hdr(host) -i cloud1.temp.com -i cloud2.temp.com
   
   use_backend chat_BE if is_chat
   use_backend cloud_BE if is_cloud
   
   #default_backend http_back
   # you can use the default backend, but in my example I don't use it

backend chat_BE
   mode http # I prefer to specify the backend mode per backend, I think it better for the abstract
   #balance roundrobin you don't need this because you only have one backend for the chat
   server chat.temp.com 172.17.0.4:4002 check
   
backend cloud_BE
   mode http # I prefer to specify the backend mode per backend, I think it better for the abstract
   #balance roundrobin you don't need this because you only have one backend for the chat
   server cloud1.temp.com 172.17.0.2:4001 check
   
listen stats
   bind *:9999
   mode http
   stats enable
   stats realm Haproxy\ Stats
   stats uri /haproxy_stats
   stats auth user:pw
   stats admin if TRUE # with this option it is possible to switch your backend-server in maintain-mode etc.

I hope that is mistake free… it’s fast written in Notepad++

All is my personal preference… You can do things different!

Greets hans0r