Files
mtusi2026lab4/infra/haproxy/haproxy.cfg
T

63 lines
2.3 KiB
INI

# Балансировщик lab3: HAProxy 3.0. Единственная публичная точка входа; API-реплики наружу не опубликованы.
global
log stdout format raw local0 notice
maxconn 4096
defaults
mode http
log global
option dontlognull
option forwardfor
# connect короткий: недоступная реплика быстро заменяется другой (redispatch)
timeout connect 1s
timeout client 30s
timeout server 30s
timeout http-request 10s
timeout http-keep-alive 5s
timeout queue 5s
retries 3
option redispatch 1
# Only retry before a connection is established: upload POST has no idempotency key.
retry-on conn-failure
# Docker DNS (127.0.0.11): адреса реплик API обновляются без перезапуска LB (scale up/down, пересоздание контейнеров).
resolvers docker
nameserver dns 127.0.0.11:53
accepted_payload_size 8192
resolve_retries 3
timeout resolve 1s
timeout retry 1s
hold valid 2s
hold nx 2s
hold other 2s
hold obsolete 2s
frontend public
bind :8080
# If the shared DB is down, live API processes still produce contract JSON,
# validate missing credentials, and serve /health/live independently of DB.
use_backend api_live if { nbsrv(api) eq 0 }
default_backend api
# Внутренний healthcheck самого LB (контейнерный HEALTHCHECK); наружу не публикуется.
frontend lb_health
bind :8081
monitor-uri /healthz
backend api
balance roundrobin
# Проверка готовности каждые 1 с; 2 неудачи подряд -> сервер исключён (обнаружение отказа <= ~3 с), 2 успеха -> возвращён.
option httpchk
http-check send meth GET uri /health/ready
http-check expect status 200
default-server check inter 1s fall 2 rise 2 resolvers docker init-addr none
server-template api 1-8 api:8080
backend api_live
balance roundrobin
option httpchk
http-check send meth GET uri /health/live
http-check expect status 200
default-server check inter 1s fall 2 rise 2 resolvers docker init-addr none
server-template api 1-8 api:8080