Hallo allerseits, wir verwenden Docker Swarm in der Produktion und stehen vor dem Problem, Container und Last über Knoten im Cluster hinweg zu verteilen. Ich möchte Ihnen sagen, auf welche Schwierigkeiten wir gestoßen sind, und unsere Lösung teilen.
1) Beschreibung des Problems
, . , 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, , , .