Skip to content

Commit e13451e

Browse files
committed
adding in cloud-quick-start
1 parent 0cf8167 commit e13451e

File tree

2 files changed

+445
-0
lines changed

2 files changed

+445
-0
lines changed
+170
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
# Service deployment on a swarm in the Cloud
2+
3+
Script that create a swarm cluster and deploy a simple service.
4+
Swarm is created with Swarm mode of Engine 1.12. Can be created on
5+
* Virtualbox
6+
* Microsoft Azure
7+
* Digitalocean
8+
* Amazon EC2
9+
10+
Note: currently, if deploying on AWS, only EU (Ireland) region is available. Make sure you use a Key Pairs for this region
11+
12+
# Usage
13+
14+
```
15+
./swarm.sh [--driver provider]
16+
[--azure-subscription-id azure_subscription_id]
17+
[--amazonec2-access-key ec2_access_key]
18+
[--amazonec2-secret-key ec2_secret_key]
19+
[--amazonec2-security-group ec2_security_group]
20+
[--digitalocean_token]
21+
[-m|--manager nbr_manager]
22+
[-w|--worker nbr_worker]
23+
[-r|--replica nbr_replica]
24+
[-p|--port exposed_port]
25+
[--service_image image_of_the_service_to_deploy]
26+
[--service_port port_exposed_by_the_service_to_deploy]
27+
```
28+
29+
Several parameters can be provided
30+
* driver used ("azure", "virtualbox", "digitalocean", "amazonec2") (default: "virtualbox")
31+
* number of manager (default: 3)
32+
* number of worker (default: 5)
33+
* number of replicas for the deployed service (lucj/randomcity:1.1) (default: 5)
34+
* port exposed by the cluster (default: 8080)
35+
* azure subscription id (if azure driver selected)
36+
* digitalocean token (if digitalocean driver specified)
37+
* amazon access key, secret key, security group (currently only for EU (Ireland) region) (if amazonec2 driver is specified)
38+
39+
# Example
40+
41+
Let's create a swarm cluster with 2 manager and 2 worker nodes locally (with virtualbox) and using service lucj/randomCity
42+
Once deployed service will be available on port 8080 (default port)
43+
44+
```
45+
$ ./swarm.sh --manager 2 --worker 2 --service_image lucj/randomCity --service_port 80
46+
-> about to create a swarm with 2 manager(s) and 2 workers on virtualbox machines
47+
-> creating Docker host for manager 1 (please wait)
48+
-> creating Docker host for manager 2 (please wait)
49+
-> creating Docker host for worker 1 (please wait)
50+
-> creating Docker host for worker 2 (please wait)
51+
-> init swarm
52+
Swarm initialized: current node (99xi3bzlgobxmeff573qitctg) is now a manager.
53+
-> join manager 2 to the swarm
54+
Node f4wocnel60xwfn2z522a645ba accepted in the swarm.
55+
-> join worker 1 to the swarm
56+
This node joined a Swarm as a worker.
57+
-> join worker 2 to the swarm
58+
This node joined a Swarm as a worker.
59+
-> deploy service with 5 replicas with exposed port 8080
60+
-> waiting for service 5ny5u5pmfw75mnomleb34a3kp to be available
61+
... retrying in 2 seconds
62+
... retrying in 2 seconds
63+
... retrying in 2 seconds
64+
... retrying in 2 seconds
65+
... retrying in 2 seconds
66+
... retrying in 2 seconds
67+
... retrying in 2 seconds
68+
... retrying in 2 seconds
69+
... retrying in 2 seconds
70+
-> service available on port 8080 of any node
71+
ID NAME REPLICAS IMAGE COMMAND
72+
5ny5u5pmfw75 city 5/5 lucj/randomcity:1.1
73+
ID NAME SERVICE IMAGE LAST STATE DESIRED STATE NODE
74+
1j157qz7nu4kaqmack4zuwibm city.1 city lucj/randomcity:1.1 Running 20 seconds Running manager1
75+
72y2off8y5f8zp4djzmjdzowg city.2 city lucj/randomcity:1.1 Running 20 seconds Running worker1
76+
efzaweh8lhj9aalrgdhnx26i0 city.3 city lucj/randomcity:1.1 Running 20 seconds Running manager2
77+
1f5ccot3wn3yhrhfbqf6vj5d5 city.4 city lucj/randomcity:1.1 Running 20 seconds Running worker2
78+
f53ummqn8mba0hzy15w08pxj4 city.5 city lucj/randomcity:1.1 Running 20 seconds Running worker2
79+
```
80+
81+
82+
# Docker hosts
83+
84+
List all Docker host created
85+
86+
```
87+
$ docker-machine ls
88+
NAME ACTIVE DRIVER STATE URL SWARM DOCKER ERRORS
89+
manager1 - virtualbox Running tcp://192.168.99.100:2376 v1.12.0-rc2
90+
manager2 - virtualbox Running tcp://192.168.99.101:2376 v1.12.0-rc2
91+
worker1 - virtualbox Running tcp://192.168.99.102:2376 v1.12.0-rc2
92+
worker2 - virtualbox Running tcp://192.168.99.103:2376 v1.12.0-rc2
93+
```
94+
95+
# Service details
96+
97+
The test service deployed is a simple http server that returns a message with
98+
* the ip of the container that handled the request
99+
* a random city of the world
100+
101+
# Test deployed service
102+
103+
Send several requests to the manager1
104+
105+
```
106+
$ curl 192.168.99.100:8080
107+
{"message":"10.255.0.7 suggests to visit Zebunto"}
108+
$ curl 192.168.99.100:8080
109+
{"message":"10.255.0.8 suggests to visit Areugpip"}
110+
$ curl 192.168.99.100:8080
111+
{"message":"10.255.0.10 suggests to visit Fozbovsav"}
112+
$ curl 192.168.99.100:8080
113+
{"message":"10.255.0.9 suggests to visit Kitunweg"}
114+
$ curl 192.168.99.100:8080
115+
{"message":"10.255.0.11 suggests to visit Aviznuk"}
116+
$ curl 192.168.99.100:8080
117+
{"message":"10.255.0.7 suggests to visit Nedhikmu"}
118+
$ curl 192.168.99.100:8080
119+
{"message":"10.255.0.8 suggests to visit Palmenme"}
120+
```
121+
122+
Send several requests to the worker2
123+
124+
```
125+
$ curl http://192.168.99.102:8080
126+
{"message":"10.255.0.8 suggests to visit Wehappap"}
127+
$ curl http://192.168.99.102:8080
128+
{"message":"10.255.0.11 suggests to visit Jocuvdam"}
129+
$ curl http://192.168.99.102:8080
130+
{"message":"10.255.0.12 suggests to visit Suvigenuh"}
131+
$ curl http://192.168.99.102:8080
132+
{"message":"10.255.0.9 suggests to visit Jinonat"}
133+
```
134+
135+
The requests are dispatched in a round robin fashion to the running containers.
136+
137+
# Examples with other drivers
138+
139+
## Run 3 managers and 6 workers on Microsoft Azure based on ehazlett/docker-demo image (default image if none specified)
140+
141+
```
142+
./swarm.sh --driver azure --azure-subscription-id $AZURE_SUBSCRIPTION_ID --manager 3 --worker 6
143+
```
144+
145+
## Run 3 managers and 6 workers on DigitalOcean and use service based on ehazlett/docker-demo image (default image if none specified)
146+
147+
```
148+
./swarm.sh --driver digitalocean --digitalocean_token $DO_TOKEN --manager 3 --worker 6
149+
```
150+
151+
Once the service is deployed you got some nice Mobydock :)
152+
153+
![Mobydock](https://dl.dropboxusercontent.com/u/2330187/docker/labs/1.12/swarm-sample/mobydock.png)
154+
155+
Note: beware of the browser cache that prevents the hostname to be updated sometimes
156+
157+
## Run 3 managers and 6 workers on AmazonEC2 based on ehazlett/docker-demo image (default image if none specified)
158+
159+
```
160+
./swarm.sh --driver amazonec2 --amazonec2-access-key $AWS_ACCESS_KEY --amazonec2-secret-key $AWS_SECRET_KEY --amazonec2-security-group default --manager 3 --worker 6
161+
```
162+
163+
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
164+
165+
# Status
166+
167+
- [ ] Azure deployment with image / size / region selection
168+
- [ ] DigitalOcean deployment with image / size / region selection
169+
- [ ] Amazon deployment with AMI / instance type / region selection
170+
- [ ] Amazon deployment with automatic opening of exposed port in SecurityGroup

0 commit comments

Comments
 (0)