HA Proxy load balancer in front of NGINX ingress controller - not working (502 Bad Gateway)

Asking for help? Comment out what you need so we can get more information to help you!

Cluster information:

Kubernetes version: v1.19.4
Cloud being used: (put bare-metal if not on a public cloud) bare-metal
Installation method: kubeadm
Host OS: CentOS 7.5 (64-bit)
CNI and version: Docker version 19.03.13
CRI and version: 3.14

I am relatively new to Kubernetes. I have deployed K8s cluster on-premises. Locally I am able to access my application UI through node port service using my worker node IP.
I am using NGINX ingress controller. I deployed haproxy as a external load balancer outside my K8s cluster.

Following are the entries for worker nodes in ha proxy config file

frontend main
  bind *:7979
  option tcplog
  default_backend http

backend http
  balance roundrobin
  server workernode1 10.221.86.37:32210 check
  server workernode2 10.221.86.38:32210 check
  server workernode3 10.221.86.39:32210 check

Following are details for NGINX ingress controller

NAME                                                 READY   STATUS  RESTARTS   AGE
pod/nginx-ingress-4q9w8                    1/1     Running   0          	2d7h
pod/nginx-ingress-55fw4                     1/1     Running   0          	2d7h
pod/nginx-ingress-cp8sj                       1/1     Running   0         	 2d7h

NAME                             TYPE            CLUSTER-IP       EXTERNAL-IP      PORT(S)                        			AGE
service/nginx-ingress    NodePort    10.99.249.144    <none>        	80:32210/TCP,443:31078/TCP      2d7h

NAME                           		DESIRED   CURRENT   READY   UP-TO-DATE   AVAILABLE   NODE SELECTOR   AGE
daemonset.apps/nginx-ingress   3         	3         	3       	3            		3           		<none>          2d7h

I have refer beneath official documentation to install ingress controller as daemonset.

Note: All cluster resources including ingress controller are in “default” namespace. I used apiVersion “networking.k8s.io/v1” for Ingress.

When I try to access the haproxy url, I can see below controller log:-

“[error] 39#39: 28 broken header: "GET / HTTP/1.1
Host: URL:port
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,
/*;q=0.8,application/signed-exchange;v=b3;q=0.9
Accept-Encoding: gzip, deflate
Accept-Language: en-GB,en;q=0.9
X-Forwarded-For: x.x.x.x
Connection: close
while reading PROXY protocol, client: 192.168.216.64, server: 0.0.0.0:80”

And over the browser I get “ 502 Bad Gateway The server returned an invalid or incomplete response “

Can anybody suggest and give some clues to resolve above said issues ??
If any further details are required, please let me know.

Thanks in advance

You can format your yaml by highlighting it and pressing Ctrl-Shift-C, it will make your output easier to read.

Issue is fixed by applying “send-proxy-v2” property in haproxy config file

server NodeName NodeIP:NodePort check send-proxy-v2