Skip to content

Instantly share code, notes, and snippets.

@cizixs cizixs/cluster.sh
Last active Apr 8, 2019

Embed
What would you like to do?
Create swarm cluster in one command.
#!/bin/bash
# This script helps to create a develop docker swarm cluster in one command
# For explanations and details, please refer to https://docs.docker.com/engine/userguide/networking/get-started-overlay/
set -e
create_kv() {
echo Creating kvstore machine.
docker-machine create -d virtualbox \
kvstore
docker $(docker-machine config kvstore) run -d \
-p "8500:8500" \
progrium/consul --server -bootstrap-expect 1
}
create_master() {
echo Creating cluster master
kvip=$(docker-machine ip kvstore)
docker-machine create -d virtualbox \
--swarm --swarm-master \
--swarm-discovery="consul://${kvip}:8500" \
--engine-opt="cluster-store=consul://${kvip}:8500" \
--engine-opt="cluster-advertise=eth1:2376" \
swarm-manager
}
create_nodes(){
kvip=$(docker-machine ip kvstore)
echo Creating cluster nodes
for i in 1 2; do
docker-machine create -d virtualbox \
--swarm \
--swarm-discovery="consul://${kvip}:8500" \
--engine-opt="cluster-store=consul://${kvip}:8500" \
--engine-opt="cluster-advertise=eth1:2376" \
swarm-node${i}
done
}
create_overlay(){
docker $(docker-machine config swarm-manager) network create \
--driver overlay \
--subnet=10.0.9.0/24 \
multi
}
teardown(){
docker-machine rm kvstore -y
docker-machine rm -y swarm-manager
for i in 1 2; do
docker-machine rm -y swarm-node${i}
done
}
case $1 in
up)
create_kv
create_master
create_nodes
;;
down)
teardown
;;
*)
echo "Unknow command..."
exit 1
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.