Docker swarm and node load balancing

Hello everyone, we are using Docker Swarm in production and we are faced with the problem of balancing containers and load across nodes in the cluster. I would like to tell you what difficulties we encountered and share our solution.

1) Description of the problem

, . , docker swarm. . php-fpm, . .

. DB1 โ€” MySQL , Docker Swarm, . โ€” Web 1 , , . , , . โ€” . 

. Swarm โ€” .

, Web 1 , . , , , . Web1, . Docker Swarm . . 

, Web 1 master , web2 โ€” worker. master , , . , . Web 2 , cloud , , . , . 

:   (Web 2) , (Web 2) . , , Docker Swarm.

, Web 2 ,   Swarm. , โ€” master (Web 1). , , Web 2. 

โ€” Web 1 Docker Swarm , . , , . Web 2 , , :

docker service update  --force 

, . 

, deploy , , . , php-fpm, , php-fpm () , . , , deploy . 

, โ€” deploy php-fpm , Swarm . , , โ€”   php-fpm - .

Docker, : , Docker Swarm placement, label . , . Docker Docker Swarm . placement , .

, php-fpm Docker Swarm Web 2. , php-fpm , , php-fpm , . Web 2 Web1, php-fpm , - . Web 2 php-fpm, , Web 1. , php-fpm, , . .

Web 2 . ci , Web 2 , . , . Docker Swarm. - , Swarm (Web 2) . 

2)

, . , , , , . , , , . , , , docker service update --force , . 

- Swarm Manager. Swarm Manager โ€” bash-, ssh, . cron . .

, cron swarm_provisioner.sh, . swarm_provisioner.sh , ssh root . . , root, swarm_provisioner.sh, root SSH_COMMAND docker ps. cron file:

SHELL=/bin/bash

*/1 * * * * /swarm_provisioner.sh "web-group" "edphp-fpm" "-p 22"

, cron swarm_provisioner.sh

, .

โ€” label. , , . โ€” , . 

โ€” , , . ed, - php-fpm. 

โ€” ssh, label . , docker service update --force

, , docker swarm . , , - .

swarm-manager:
 image: swarm-manager:latest
 volumes:
   - /var/run/docker.sock:/var/run/docker.sock:ro
   - /swarm-keys:/root/.ssh
 deploy:
   replicas: 1
   update_config:
     parallelism: 1
     delay: 1s
     order: start-first
   restart_policy:
     condition: on-failure
   placement:
     constraints:
       - node.role==manager

3)

, . . ,  ssh docker api, , , .

.




All Articles