From: Kai Moritz Date: Sun, 15 Jan 2023 16:27:10 +0000 (+0100) Subject: feat: Working config for HAProxy mit mapping via `X-Shard` (casesensitive!) X-Git-Url: http://juplo.de/gitweb/?a=commitdiff_plain;h=3799ee0bd52a72b668f640430873ec1e2d819b43;p=demos%2Fkafka%2Fchat feat: Working config for HAProxy mit mapping via `X-Shard` (casesensitive!) --- diff --git a/docker-compose.yml b/docker-compose.yml index 6d093704..28fca8b5 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -88,18 +88,26 @@ services: image: haproxy:2.7 volumes: - ./haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg:ro + - ./sharding.map:/usr/local/etc/haproxy/sharding.map:ro sysctls: net.ipv4.ip_unprivileged_port_start: 0 ports: - - 8080:80 + - 8080:8400 + - 8401:8401 - 8404:8404 - web1: - image: nginx:1.17 - web2: - image: nginx:1.17 - web3: - image: nginx:1.17 + backend-1: + image: jmalloc/echo-server:latest + ports: + - 8081:8080 + backend-2: + image: jmalloc/echo-server:latest + ports: + - 8082:8080 + backend-3: + image: jmalloc/echo-server:latest + ports: + - 8083:8080 setup: image: juplo/toolbox diff --git a/haproxy.cfg b/haproxy.cfg index f334457c..0dd9ac52 100644 --- a/haproxy.cfg +++ b/haproxy.cfg @@ -7,6 +7,10 @@ defaults timeout http-request 10s log global +global + stats socket ipv4@:8401 level admin + stats timeout 2m + frontend stats bind *:8404 stats enable @@ -14,10 +18,15 @@ frontend stats stats refresh 10s frontend frontend - bind :80 - default_backend webservers + bind :8400 + use_backend %[req.hdr(X-Shard),map(/usr/local/etc/haproxy/sharding.map)] + +backend backend_1 + server b1 backend-1:8080 check + +backend backend_2 + server b2 backend-2:8080 check + +backend backend_3 + server b3 backend-3:8080 check -backend webservers - server s1 web1:80 check - server s2 web2:80 check - server s3 web3:80 check diff --git a/sharding.map b/sharding.map new file mode 100644 index 00000000..ffdbb6cb --- /dev/null +++ b/sharding.map @@ -0,0 +1,10 @@ +0 backend_3 +1 backend_1 +2 backend_2 +3 backend_3 +4 backend_1 +5 backend_2 +6 backend_3 +7 backend_1 +8 backend_2 +9 backend_3