We are looking to use HAProxy in a Kubernetes environment to proxy http requests to specific pods based on the content of the body in the http post request. The body contains a json object {customer: name} that we want to route to the internal service http://name-service.local
We have approximately 50,000 pods each with a unique service (IP) with new pods created and destroyed dynamically all the time.
Basically I want to dynamically choose where to proxy the requests by grabbing a piece of data from the http request (which can be any value), using that data to resolve a dns name, and then forward the request to the resulting service.
I was able to achieve something similar in nginx with cookies using the configuration shown below. I would like to know if it is possible to replicate this in HAProxy without having to specify all 50,000 backend servers in the configuration file?
Example Nginix configuration:
server {
listen 80;
resolver 10.21.9.15;
location / {
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $host;
set $dbname $cookie_dbname;
set $upstream_server $dbname-service.default.svc.cluster.local;
proxy_pass http://$upstream_server$request_uri;
}