Keepalived manage virtual ip between servers. Containers health can be checked to keep the virtual ip on the node.
Kernel module : ip_vs on the nodes - modprob ip_vs
- 1.2 (docker tags:
1.2
,latest
) : works only on docker host debian jessie and ubuntu trusty - 1.2-dockerinside (docker tags:
1.2-dockerinside-1.10
,1.2-dockerinside-1.11
)
VIRTUAL_IP
: VIP, by default 192.168.254.254/32VIRTUAL_ROUTER_ID
: must be the same in all nodesINTERFACE
: interface to set virtual IPPRIORITY
: 101 on master, 100 on backupsPASSWORD
: Need the same on all nodesCONTAINERS_TO_CHECK
: containers name list to check health, separated by single spaceCHECK_FALL
: require X failures for KOCHECK_RISE
: require X successes for OKCHECK_CREATION
: if true, please define the $SWARM_ADDR, $SWARM_CERTS and $CHECK_HEALTH_IMAGECHECK_HEALTH_IMAGE
: if $CHECK_CREATION, image to use to create a container every $CHECK_INTERVALSWARM_ADDR
: default to 127.0.0.1:4000SWARM_CERTS
: The path to Swarm certificats (ca.pem, cert.pem, key.pem), by default /root/.docker/CHECK_INTERVAL
: Check health of $CONTAINERS_TO_CHECK,$CHECK_CREATION) every $CHECK_INTERVAL seconds, by default 5sENABLE_LB
: Enable Load balancer config, if true, please define $REAL_IP, $REAL_PORTS, $LB_ALGO and $LB_KINDVIRTUAL_IP_LB
: IP for LB; This IP will be shared by all the nodes, by default 192.168.254.253/32REAL_IP
: Real address of the Backend Nodes separated by single spaceREAL_PORTS
: Real ports exposed on hosts separated by single space to LoadBalancingLB_ALGO
: LoadBalancing AlgotythmLB_KIND
: LoadBalancing Method
docker run -d --name keepalived --restart=always --net=host --cap-add=NET_ADMIN \
-e VIRTUAL_IP='1.1.1.1' \
-e VIRTUAL_ROUTER_ID='51' \
-e INTERFACE='eth0' \
-e PRIORITY='100' \
-e PASSWORD=topsecret \
-e CONTAINERS_TO_CHECK="container_name_1 container_name_2" \
-e CHECK_FALL='1' \
-e CHECK_RISE='1' \
-e CHECK_CREATION='true' \
-e CHECK_HEALTH_IMAGE='alpine' \
-e SWARM_ADDR='127.0.0.1:4000' \
-e SWARM_CERTS='/root/.docker/' \
-e CHECK_INTERVAL='7' \
-e ENABLE_LB='true' \
-e VIRTUAL_IP_LB='1.1.1.2' \
-e REAL_IP="1.1.1.30 1.1.1.31 1.1.1.32" \
-e REAL_PORTS='80 443' \
-e LB_ALGO='lblcr' \
-e LB_KIND='DR' \
-v /var/run/docker.sock:/var/run/docker.sock \
-v /usr/bin/docker:/usr/bin/docker \
-v /usr/lib/x86_64-linux-gnu/:/usr/lib/x86_64-linux-gnu/:ro \
-v /lib/x86_64-linux-gnu:/lib/x86_64-linux-gnu \
-v /root/.docker:/root/.docker \
alterway/keepalived:1.2
docker run -d --name keepalived --restart=always --net=host --cap-add=NET_ADMIN \
-e VIRTUAL_IP='1.1.1.1' \
-e VIRTUAL_ROUTER_ID='51' \
-e INTERFACE='eth0' \
-e PRIORITY='100' \
-e PASSWORD=topsecret \
-e CONTAINERS_TO_CHECK="container_name_1 container_name_2" \
-e CHECK_FALL='1' \
-e CHECK_RISE='1' \
-e CHECK_CREATION='true' \
-e CHECK_HEALTH_IMAGE='alpine' \
-e SWARM_ADDR='127.0.0.1:4000' \
-e SWARM_CERTS='/root/.docker/' \
-e CHECK_INTERVAL='7' \
-e ENABLE_LB='true' \
-e VIRTUAL_IP_LB='1.1.1.2' \
-e REAL_IP="1.1.1.30 1.1.1.31 1.1.1.32" \
-e REAL_PORTS='80 443' \
-e LB_ALGO='lblcr' \
-e LB_KIND='DR' \
-v /var/run/docker.sock:/var/run/docker.sock \
-v /root/.docker:/root/.docker \
alterway/keepalived:1.2
View LICENSE for the software contained in this image.