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
timeout http-request 10s
log global
+global
+ stats socket ipv4@:8401 level admin
+ stats timeout 2m
+
frontend stats
bind *:8404
stats enable
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