## LAB 41: HA Proxy Load balancer Your final architecture will be: ``` Client → HAProxy (Public IP) → NodePorts → Ingress Controller → Services → Pods ``` # 🧱 STEP 1 — Install HAProxy on Your LB VM ```bash sudo apt update sudo apt install -y haproxy ``` Check version: ```bash haproxy -v ``` --- # ⚙️ STEP 2 — Create HAProxy Config for Multiple Ingress Hosts We’ll support two domains: * **fileshare.local → nginx ingress** Open HAProxy config: ```bash sudo nano /etc/haproxy/haproxy.cfg ``` Replace with: ```haproxy global log /dev/log local0 maxconn 2048 defaults log global mode http option httplog timeout connect 5s timeout client 50s timeout server 50s # FRONTEND: receives all HTTP traffic frontend http_front bind *:80 # Map by Host header acl host_fileshare hdr(host) -i fileshare.local use_backend nginx_ingress if host_fileshare # Default (if host doesn't match) default_backend nginx_ingress # BACKEND: NGINX ingress (NodePort 32252) backend nginx_ingress balance roundrobin mode http server node_master 3.239.117.77:32252 check server node_worker1 35.171.244.121:32252 check server node_worker2 44.197.102.217:32252 check ``` Save & exit. --- # 🔄 STEP 3 — Restart HAProxy ```bash sudo systemctl restart haproxy sudo systemctl enable haproxy sudo systemctl status haproxy ``` Expected: ``` Active: active (running) ``` --- --- # 🌍 STEP 5 — Add Local DNS Entries On your laptop/workstation: ```text <HAProxy_PUBLIC_IP> fileshare.local <HAProxy_PUBLIC_IP> fileshare-traefik.local ``` --- # 🔍 STEP 6 — Test NGINX Ingress ```bash curl -I -H "Host: fileshare.local" http://34.239.175.190/ ``` Expected: `HTTP/1.1 200 OK` --- # 🧩 OPTIONAL — Load Balance MySQL, Redis, Postgres, etc. To balance MySQL port 3306: ```haproxy frontend mysql_front bind *:3306 mode tcp default_backend mysql_back backend mysql_back mode tcp balance roundrobin server db1 3.239.117.77:3306 check server db2 35.171.244.121:3306 check server db3 44.197.102.217:3306 check ``` HAProxy is both: * **L7 Reverse Proxy (HTTP/TLS)** * **L4 Network Load Balancer (TCP)**