HAproxy image that autoreconfigures itself when used in Docker Swarm Mode.
3.7K
https://github.com/rlagutinhub/docker_swarm-mode.haproxy-balancer
Requirements:
Tested:
Docker SDK Example:
import json
import docker
# client = docker.from_env()
client = docker.DockerClient(base_url='unix://var/run/docker.sock')
client.services.list()
[<Service: ww2hfyddw3>, <Service: yq45gxwxhl>]
srv = client.services.get('yq45gxwxhl')
srv.name
srv.attrs
srv.tasks()
print(json.dumps(srv.tasks(), indent=4))
client.networks.list()
net = client.networks.get('xjaz5s7r5x')
net.name
net.attrs
git clone https://github.com/rlagutinhub/docker_swarm-mode.haproxy-balancer.git
cd docker_swarm-mode.haproxy-balancer
Docker Image:
docker build -t rlagutinhub/docker_swarm-mode.haproxy-balancer .
docker network create -d overlay haproxy-balancer_prod
Create haproxy-balancer
docker service create --detach=false \
--name haproxy-balancer \
--network haproxy-balancer_prod \
--mount target=/var/run/docker.sock,source=/var/run/docker.sock,type=bind \
--mode global \
--constraint "node.role == manager" \
rlagutinhub/docker_swarm-mode.haproxy-balancer:latest
enable autconfigure haproxy-balancer
docker service update --detach=false haproxy-balancer \
--label-add "com.example.proxy=true"
custom default settings haproxy-balancer
docker service update --detach=false haproxy-balancer \
--label-add "com.example.def_log_server=127.0.0.1" \
--label-add "com.example.def_retries=3" \
--label-add "com.example.def_timeout_http_request=10s" \
--label-add "com.example.def_timeout_queue=1m" \
--label-add "com.example.def_timeout_connect=10s" \
--label-add "com.example.def_timeout_client=1m" \
--label-add "com.example.def_timeout_server=1m" \
--label-add "com.example.def_timeout_http_keep_alive=10s" \
--label-add "com.example.def_timeout_check=10s" \
--label-add "com.example.def_maxconn=10000" \
--label-add "com.example.stats_port=1936" \
--label-add "com.example.stats_login=root" \
--label-add "com.example.stats_password=password"
custom configure rsyslog server for haproxy Configure on the server, which is defined in the def_log_server.
vim /etc/rsyslog.conf (uncomment or add)
$ModLoad imudp
$UDPServerRun 514
local2.* /var/log/haproxy.log
ssl certificate - https forntend with tcp443 (docker secrets)
cat server.crt server.key > 443.pem
docker secret create haproxy-balancer_201711061830_443.pem 443.pem
docker service update --detach=false \
--secret-rm haproxy-balancer_OLD_443.pem \
--secret-add source=haproxy-balancer_201711061830_443.pem,target=/etc/pki/tls/certs/443.pem,mode=0644 \
haproxy-balancer
ssl certificate - https forntend with tcp8443 (docker secrets)
cat server.crt server.key > 8443.pem
docker secret create haproxy-balancer_201711061830_8443.pem 8443.pem
docker service update --detach=false \
--secret-rm haproxy-balancer_OLD_8443.pem \
--secret-add source=haproxy-balancer_201711061830_8443.pem,target=/etc/pki/tls/certs/8443.pem,mode=0644 \
haproxy-balancer
create app
docker service create --detach=false \
--name haproxy-test \
-e PORTS="8080, 8081, 8443, 8444, 10001, 10002" \
--network haproxy-balancer_prod \
--constraint "node.role != manager" \
rlagutinhub/docker_swarm-mode.haproxy-test:201711111920
enable autconfigure haproxy-balancer
docker service update --detach=false haproxy-test \
--label-add "com.example.proxy=true" \
--label-add "com.example.proxy_name=haproxy-balancer" \
--label-add "com.example.proxy_net=haproxy-balancer_prod"
proxy http with sticky session
docker service update --detach=false haproxy-test \
--label-add "com.example.proxy_http_name1=http-sticky-true.example.com" \
--label-add "com.example.proxy_http_front1=80" \
--label-add "com.example.proxy_http_back1=8080" \
--label-add "com.example.proxy_http_sticky1=true"
proxy http without sticky session
docker service update --detach=false haproxy-test \
--label-add "com.example.proxy_http_name2=http-sticky-false.example.com" \
--label-add "com.example.proxy_http_front2=80" \
--label-add "com.example.proxy_http_back2=8081" \
--label-add "com.example.proxy_http_sticky2=false"
proxy https with sticky session
docker service update --detach=false haproxy-test \
--label-add "com.example.proxy_https_name1=https-sticky-true.example.com" \
--label-add "com.example.proxy_https_front1=443" \
--label-add "com.example.proxy_https_back1=8443" \
--label-add "com.example.proxy_https_sticky1=true"
proxy https without sticky session
docker service update --detach=false haproxy-test \
--label-add "com.example.proxy_https_name2=https-sticky-false.example.com" \
--label-add "com.example.proxy_https_front2=443" \
--label-add "com.example.proxy_https_back2=8444" \
--label-add "com.example.proxy_https_sticky2=false"
proxy tcp with sticky session
docker service update --detach=false haproxy-test \
--label-add "com.example.proxy_tcp_front1=10001" \
--label-add "com.example.proxy_tcp_back1=10001" \
--label-add "com.example.proxy_tcp_sticky1=true"
proxy tcp without sticky session
docker service update --detach=false haproxy-test \
--label-add "com.example.proxy_tcp_front2=10002" \
--label-add "com.example.proxy_tcp_back2=10002" \
--label-add "com.example.proxy_tcp_sticky2=false"
Content type
Image
Digest
Size
142.9 MB
Last updated
almost 9 years ago
docker pull rlagutinhub/docker_swarm-mode.haproxy-balancer