Forked from zerowebcorp/docker-swarm-auto-rebalance.sh
Last active
September 30, 2020 17:47
-
-
Save Artem-Schander/86f058860e1be61fd342237b93818f8d to your computer and use it in GitHub Desktop.
Docker Swarm automatically rebalance when new worker node joins
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FILE=/tmp/worker.nodes | |
touch ${FILE} || exit | |
for node in `docker node ls --filter role=worker -q`; do | |
if grep -Fxq "${node}" ${FILE} | |
then | |
echo "This node ${node} already exists" | |
else | |
echo "This node ${node} joined recently, so rebalance" | |
for service in `docker service ls -q`; do | |
docker service update --with-registry-auth --detach=true --force ${service} | |
done | |
fi | |
done | |
docker node ls --filter role=worker -q > ${FILE} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Or
docker service ls -q > dkr_svcs && for i in
cat dkr_svcs; do docker service update "$i" --detach=false --force ; done