Merge pull request #26 from gianarb/feature/demo

Added swarm demo
This commit is contained in:
Gianluca Arbezzano 2017-08-08 20:47:44 +02:00 committed by GitHub
commit 29cfd3d109
5 changed files with 152 additions and 1 deletions

View File

@ -12,9 +12,12 @@ We designed in collaboration with InfluxData to show how metrics can be used.
It is based on plugins called `provider`. At the moment we implemented:
* Docker Swarm mode [(go to zero-conf
chapter](https://github.com/gianarb/orbiter#autodetect)
chapter](https://github.com/gianarb/orbiter#autodetect). look full example
under `./contrib/swarm` directory
* DigitalOcean
```sh
orbiter daemon -config config.yml
```

15
contrib/swarm/Makefile Normal file
View File

@ -0,0 +1,15 @@
IP = $(shell docker-machine ip sw1)
init:
./cluster/create.sh
destroy:
docker-machine rm -f sw1 sw2 sw3 sw4
deploy:
docker stack deploy --compose-file stack.yml stack
ps:
docker service ls
docker stack ps stack
scale-up:
curl -X POST -v http://$(IP):8081/handle/autodetect_swarm/stack_micro/up
scale-down:
curl -X POST -v http://$(IP):8081/handle/autodetect_swarm/stack_micro/down

57
contrib/swarm/README.md Normal file
View File

@ -0,0 +1,57 @@
This is a tutorial to use orbiter as autoscaler with Docker Swarm.
Requirements:
* Docker CLI installed
* Docker Machine
* Virtualbox
1. Create a swarm cluster with 4 nodes. One manager and three workers. It uses
Docker Machine and Virtualbox as provider.
```
make init
```
2. Point Docker CLI to the right Docker machine. The master is called sw1.
```
eval $(docker-machine env sw1)
```
3. Deploy your stack. The stack contains two services, one called orbiter and
another called micro. Micro is the web app that we are autoscaling.
```
make deploy
```
4. This command shows the current situation. The first table represent the
number of services and how many task are running under a service. You should
see two services. Micro has 10 tasks.
```
make ps
```
5. There is an utility in the makefile to scale up and down micro.
```
make scale-up
make scale-down
```
6. You can check the number of tasks changing every time you scale with the
command:
```
make ps
```
7. At the end of the test you can clean your envrionment
```
make destroy
```
That's it. Have a look at the code in `./stack.yml` and `Makefile` to have more
information about how orbiter works.

26
contrib/swarm/cluster/create.sh Executable file
View File

@ -0,0 +1,26 @@
#!/bin/bash
provider=virtualbox
echo "### Init Servers ###"
docker-machine create -d ${provider} sw1 &
docker-machine create -d ${provider} sw2 &
docker-machine create -d ${provider} sw3 &
docker-machine create -d ${provider} sw4 &
wait
echo "### Configurate cluster ###"
MANAGER_IP=$(docker-machine ip sw1)
docker-machine ssh sw1 docker swarm init --advertise-addr ${MANAGER_IP}
TOKEN=$(docker-machine ssh sw1 docker swarm join-token -q worker)
docker-machine ssh sw2 docker swarm join --token ${TOKEN} ${MANAGER_IP}:2377
docker-machine ssh sw3 docker swarm join --token ${TOKEN} ${MANAGER_IP}:2377
docker-machine ssh sw4 docker swarm join --token ${TOKEN} ${MANAGER_IP}:2377
# Information
echo ""
echo "CLUSTER INFORMATION"
echo "discovery token: ${TOKEN}"
echo "Environment variables to connect trough docker cli"
docker-machine env sw1

50
contrib/swarm/stack.yml Normal file
View File

@ -0,0 +1,50 @@
version: '3'
services:
orbiter:
image: gianarb/orbiter
command: daemon
ports:
- 8081:8000
volumes:
- /var/run/docker.sock:/var/run/docker.sock
deploy:
placement:
constraints:
- node.role == manager
mode: replicated
replicas: 1
resources:
limits:
cpus: '0.25'
memory: 512M
reservations:
cpus: '0.25'
memory: 256M
micro:
image: gianarb/micro:1.2.0
labels: [orbiter=true]
networks:
- micro-net
ports:
- 8000:8000
deploy:
mode: replicated
replicas: 10
labels: [orbiter=true]
update_config:
parallelism: 2
delay: 3s
resources:
limits:
cpus: '0.25'
memory: 512M
reservations:
cpus: '0.25'
memory: 256M
restart_policy:
condition: on-failure
delay: 3s
max_attempts: 3
window: 5s
networks:
micro-net: