forked from docker/labs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create a Swarm with swarm mode and deploy a service on VirtualBox, Di…
…gitalOcean, AWS (docker#28) * First version * Add additional details * Add example of a run * Add requests example * Typo * Enhance version with additional parameters * Add additional details * Typo * Example of request targetting a worker * Add option to deploy the sample service on DigitalOcean * Add dpeloyment on amazonec2 * Add missing parameters in descripion * remove unnecessary echos * Enables to run a public image
- Loading branch information
Showing
2 changed files
with
413 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,163 @@ | ||
# Service deployment on a swarm | ||
|
||
Script that create a swarm cluster and deploy a simple service. | ||
Swarm is created with Swarm mode of Engine 1.12. Can be created on | ||
* Virtualbox | ||
* Digitalocean | ||
* Amazon EC2 | ||
|
||
Note: currently, if deploying on AWS, only EU (Ireland) region is available. Make sure you use a Key Pairs for this region | ||
|
||
# Usage | ||
|
||
``` | ||
./swarm.sh [--driver provider] | ||
[--amazonec2-access-key ec2_access_key] | ||
[--amazonec2-secret-key ec2_secret_key] | ||
[--amazonec2-security-group ec2_security_group] | ||
[--digitalocean_token] | ||
[-m|--manager nbr_manager] | ||
[-w|--worker nbr_worker] | ||
[-r|--replica nbr_replica] | ||
[-p|--port exposed_port] | ||
[--service_image image_of_the_service_to_deploy] | ||
[--service_port port_exposed_by_the_service_to_deploy] | ||
``` | ||
|
||
Several parameters can be provided | ||
* driver used ("virtualbox", "digitalocean", "amazonec2") (default: "virtualbox") | ||
* number of manager (default: 3) | ||
* number of worker (default: 5) | ||
* number of replicas for the deployed service (lucj/randomcity:1.1) (default: 5) | ||
* port exposed by the cluster (default: 8080) | ||
* digitalocean token (if digitalocean driver specified) | ||
* amazon access key, secret key, security group (currently only for EU (Ireland) region) (if amazonec2 driver is specified) | ||
|
||
# Example | ||
|
||
Let's create a swarm cluster with 2 manager and 2 worker nodes locally (with virtualbox) and using service lucj/randomCity | ||
Once deployed service will be available on port 8080 (default port) | ||
|
||
``` | ||
$ ./swarm.sh --manager 2 --worker 2 --service_image lucj/randomCity --service_port 80 | ||
-> about to create a swarm with 2 manager(s) and 2 workers on virtualbox machines | ||
-> creating Docker host for manager 1 (please wait) | ||
-> creating Docker host for manager 2 (please wait) | ||
-> creating Docker host for worker 1 (please wait) | ||
-> creating Docker host for worker 2 (please wait) | ||
-> init swarm | ||
Swarm initialized: current node (99xi3bzlgobxmeff573qitctg) is now a manager. | ||
-> join manager 2 to the swarm | ||
Node f4wocnel60xwfn2z522a645ba accepted in the swarm. | ||
-> join worker 1 to the swarm | ||
This node joined a Swarm as a worker. | ||
-> join worker 2 to the swarm | ||
This node joined a Swarm as a worker. | ||
-> deploy service with 5 replicas with exposed port 8080 | ||
-> waiting for service 5ny5u5pmfw75mnomleb34a3kp to be available | ||
... retrying in 2 seconds | ||
... retrying in 2 seconds | ||
... retrying in 2 seconds | ||
... retrying in 2 seconds | ||
... retrying in 2 seconds | ||
... retrying in 2 seconds | ||
... retrying in 2 seconds | ||
... retrying in 2 seconds | ||
... retrying in 2 seconds | ||
-> service available on port 8080 of any node | ||
ID NAME REPLICAS IMAGE COMMAND | ||
5ny5u5pmfw75 city 5/5 lucj/randomcity:1.1 | ||
ID NAME SERVICE IMAGE LAST STATE DESIRED STATE NODE | ||
1j157qz7nu4kaqmack4zuwibm city.1 city lucj/randomcity:1.1 Running 20 seconds Running manager1 | ||
72y2off8y5f8zp4djzmjdzowg city.2 city lucj/randomcity:1.1 Running 20 seconds Running worker1 | ||
efzaweh8lhj9aalrgdhnx26i0 city.3 city lucj/randomcity:1.1 Running 20 seconds Running manager2 | ||
1f5ccot3wn3yhrhfbqf6vj5d5 city.4 city lucj/randomcity:1.1 Running 20 seconds Running worker2 | ||
f53ummqn8mba0hzy15w08pxj4 city.5 city lucj/randomcity:1.1 Running 20 seconds Running worker2 | ||
``` | ||
|
||
|
||
# Docker hosts | ||
|
||
List all Docker host created | ||
|
||
``` | ||
$ docker-machine ls | ||
NAME ACTIVE DRIVER STATE URL SWARM DOCKER ERRORS | ||
manager1 - virtualbox Running tcp://192.168.99.100:2376 v1.12.0-rc2 | ||
manager2 - virtualbox Running tcp://192.168.99.101:2376 v1.12.0-rc2 | ||
worker1 - virtualbox Running tcp://192.168.99.102:2376 v1.12.0-rc2 | ||
worker2 - virtualbox Running tcp://192.168.99.103:2376 v1.12.0-rc2 | ||
``` | ||
|
||
# Service details | ||
|
||
The test service deployed is a simple http server that returns a message with | ||
* the ip of the container that handled the request | ||
* a random city of the world | ||
|
||
# Test deployed service | ||
|
||
Send several requests to the manager1 | ||
|
||
``` | ||
$ curl 192.168.99.100:8080 | ||
{"message":"10.255.0.7 suggests to visit Zebunto"} | ||
$ curl 192.168.99.100:8080 | ||
{"message":"10.255.0.8 suggests to visit Areugpip"} | ||
$ curl 192.168.99.100:8080 | ||
{"message":"10.255.0.10 suggests to visit Fozbovsav"} | ||
$ curl 192.168.99.100:8080 | ||
{"message":"10.255.0.9 suggests to visit Kitunweg"} | ||
$ curl 192.168.99.100:8080 | ||
{"message":"10.255.0.11 suggests to visit Aviznuk"} | ||
$ curl 192.168.99.100:8080 | ||
{"message":"10.255.0.7 suggests to visit Nedhikmu"} | ||
$ curl 192.168.99.100:8080 | ||
{"message":"10.255.0.8 suggests to visit Palmenme"} | ||
``` | ||
|
||
Send several requests to the worker2 | ||
|
||
``` | ||
$ curl http://192.168.99.102:8080 | ||
{"message":"10.255.0.8 suggests to visit Wehappap"} | ||
$ curl http://192.168.99.102:8080 | ||
{"message":"10.255.0.11 suggests to visit Jocuvdam"} | ||
$ curl http://192.168.99.102:8080 | ||
{"message":"10.255.0.12 suggests to visit Suvigenuh"} | ||
$ curl http://192.168.99.102:8080 | ||
{"message":"10.255.0.9 suggests to visit Jinonat"} | ||
``` | ||
|
||
The requests are dispatched in a round robin fashion to the running containers. | ||
|
||
# Examples with other drivers | ||
|
||
## Run 3 managers and 6 workers on DigitalOcean and use service based on ehazlett/docker-demo image (default image if none specified) | ||
|
||
``` | ||
./swarm.sh --driver digitalocean --digitalocean_token $DO_TOKEN --manager 3 --worker 6 | ||
``` | ||
|
||
Once the service is deployed you got some nice Mobydock :) | ||
|
||
![Mobydock](https://dl.dropboxusercontent.com/u/2330187/docker/labs/1.12/swarm-sample/mobydock.png) | ||
|
||
Note: beware of the browser cache that prevents the hostname to be updated sometimes | ||
|
||
## Run 3 managers and 6 workers on AmazonEC2 based on ehazlett/docker-demo image (default image if none specified) | ||
|
||
``` | ||
./swarm.sh --driver amazonec2 --amazonec2-access-key $AWS_ACCESS_KEY --amazonec2-secret-key $AWS_SECRET_KEY --amazonec2-security-group default --manager 3 --worker 6 | ||
``` | ||
|
||
note: make sure the security group provided (**default** in this example) allow communication between hosts and open the exposed port (8080 by default) to the outside | ||
|
||
# Status | ||
|
||
- [x] Virtualbox deployment | ||
- [x] Digitalocean deployment (Ubuntu 14.04 / 1gb / lon1) | ||
- [x] Amazon deployment (Ubuntu 14.04 / t2.micro / EU (Ireland)) | ||
- [ ] DigitalOcean deployment with image / size / region selection | ||
- [ ] Amazon deployment with AMI / instance type / region selection | ||
- [ ] Amazon deployment with automatic opening of exposed port in SecurityGroup |
Oops, something went wrong.