Skip to content

Commit 4111501

Browse files
author
Matthew Fisher
committed
refactor(contrib): update Deis deployment on AWS
The old contrib scripts used to assist with distributing an AMI with Deis preconfigured for both the controller and for the nodes across Amazon EC2 regions. It also helped with spawning a node on EC2 using the controller AMI, then bootstrapped the node so that the node would be added to Chef. The AMI was meant to help speed up the bootstrap process, as it pulled the latest Deis components onto the AMI as well as the Docker daemon along with a couple other packages. With the shift to the scheduler, we no longer manage the difference between controller, proxy and runtime nodes. We let https://github.com/coreos/fleet do the heavy lifting for us. Instead, we communicate with a CoreOS cluster and upload a couple of systemd units onto the cluster. With that shift in thought, we can leverage Amazon CloudFormation to bootstrap a CoreOS cluster and then do the rest remotely with fleetctl.
1 parent 57cde57 commit 4111501

10 files changed

Lines changed: 152 additions & 387 deletions

.gitignore

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,5 @@ Vagrantfile.local
5656
.bundle
5757
/__init__.py
5858

59-
# Chef setup
60-
.chef
61-
contrib/vagrant/knife-config/admin.pem
62-
contrib/vagrant/knife-config/chef-validator.pem
59+
# EC2 CloudFormation Setup
60+
contrib/ec2/cloudformation.json

contrib/check-deis-deps.sh

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -9,31 +9,3 @@ if ! which git > /dev/null; then
99
echo_red 'Please install git and ensure it is in your $PATH.'
1010
exit 1
1111
fi
12-
13-
# check for RubyGems and friends
14-
if ! which ruby > /dev/null; then
15-
echo_red 'Please install ruby and ensure it is in your $PATH.'
16-
exit 1
17-
fi
18-
if ! which gem > /dev/null; then
19-
echo_red 'Please install RubyGems and ensure "gem" is in your $PATH.'
20-
exit 1
21-
fi
22-
if ! which bundle > /dev/null; then
23-
echo_red 'Please install the bundler ruby gem and ensure "bundle" is in your $PATH.'
24-
exit 1
25-
fi
26-
bundles=`bundle list | egrep 'berkshelf|chef|foodcritic|knife-' | wc -l`
27-
if ! [ $bundles -ge 4 ]; then
28-
echo_red 'Please run "bundle install" for required ruby gems.'
29-
exit 1
30-
fi
31-
# check for working knife
32-
if ! which knife > /dev/null; then
33-
echo_red 'Please install a knife-<provider> ruby gem and ensure "knife" is in your $PATH.'
34-
exit 1
35-
fi
36-
if ! bundle exec knife client list > /dev/null; then
37-
echo_red 'Please ensure the knife.rb file is set up correctly for your Chef account.'
38-
exit 1
39-
fi

contrib/ec2/README.md

Lines changed: 77 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,90 @@
1-
Provision a Deis Controller on Amazon EC2
2-
=========================================
1+
Provision a Deis Cluster on Amazon EC2
2+
======================================
33

4-
1. Install [knife-ec2][knifec2] with `gem install knife-ec2` or just
5-
`bundle install` from the root directory of your deis repository:
4+
1. Install the [AWS Command Line Interface][aws-cli]:
65
```console
7-
$ cd $HOME/projects/deis
8-
$ gem install knife-ec2
9-
Fetching: knife-ec2-0.6.4.gem (100%)
10-
Successfully installed knife-ec2-0.6.4
11-
1 gem installed
12-
Installing ri documentation for knife-ec2-0.6.4...
13-
Installing RDoc documentation for knife-ec2-0.6.4...
6+
$ pip install awscli
7+
Downloading/unpacking awscli
8+
Downloading awscli-1.3.6.tar.gz (173kB): 173kB downloaded
9+
...
1410
```
1511

16-
2. Export your EC2 credentials as environment variables and edit knife.rb
17-
to read them:
12+
2. Run `aws configure` to set your AWS credentials:
1813
```console
19-
$ cat <<'EOF' >> $HOME/.bash_profile
20-
export AWS_ACCESS_KEY=<your_aws_access_key>
21-
export AWS_SECRET_KEY=<your_aws_secret_key>
22-
EOF
23-
$ source $HOME/.bash_profile
24-
$ cat <<'EOF' >> $HOME/.chef/knife.rb
25-
knife[:aws_access_key_id] = "#{ENV['AWS_ACCESS_KEY']}"
26-
knife[:aws_secret_access_key] = "#{ENV['AWS_SECRET_KEY']}"
27-
EOF
28-
$ knife ec2 server list
29-
Instance ID Name Public IP Private IP Flavor Image SSH Key Security Groups State
14+
$ aws configure
15+
AWS Access Key ID [None]: ***************
16+
AWS Secret Access Key [None]: ************************
17+
Default region name [None]: us-west-1
18+
Default output format [None]:
3019
```
3120

32-
3. Download and install the [EC2 Command Line Tools][ec2cli] as described in
33-
[AWS' documentation][ec2cli] and ensure they are available in your $PATH:
21+
3. Upload a new keypair to AWS, ensuring that the name of the keypair is set to "deis".
22+
23+
4. Edit [cloudformation-parameters.json][cf-params], ensuring to add a new discovery URL.
24+
You can get a new one by sending a new request to http://discovery.etcd.io/new.
25+
```console
26+
{
27+
"ParameterKey": "DiscoveryURL",
28+
"ParameterValue": "https://discovery.etcd.io/40826e8da55f4d9026935ab67b243c6a"
29+
}
30+
```
31+
NOTE: If you're interested in running your own discovery endpoint or want to know more
32+
about the discovery URL, see http://discovery.etcd.io for more information. You can also
33+
read more on how you can customize this cluster by looking at the
34+
[CoreOS EC2 template][template] and applying it to
35+
[cloudformation-parameters.json][cf-params].
36+
37+
5. Run the [cloudformation provision script][pro-script] to spawn a new CoreOS cluster:
3438
```console
35-
$ ec2-describe-group
36-
GROUP sg-33d1045a 693041077886 default default group
37-
PERMISSION 693041077886 default ALLOWS tcp 0 65535 FROM USER 693041077886 NAME default ID sg-33d1045a ingress
38-
PERMISSION 693041077886 default ALLOWS udp 0 65535 FROM USER 693041077886 NAME default ID sg-33d1045a ingress
39-
PERMISSION 693041077886 default ALLOWS icmp -1 -1 FROM USER 693041077886 NAME default ID sg-33d1045a ingress
39+
$ ./provision-ec2-cluster.sh
40+
{
41+
"StackId": "arn:aws:cloudformation:us-west-1:413516094235:stack/deis/9699ec20-c257-11e3-99eb-50fa01cd4496"
42+
}
43+
Your Deis cluster has successfully deployed.
44+
Please wait for it to come up, then run ./initialize-ec2-cluster.sh
4045
```
4146

42-
4. Run the provisioning script to create a new Deis controller:
47+
6. Once the cluster is up, get the hostname of any of the machines from EC2, set
48+
FLEETCTL_TUNNEL, then run [the init script][init-script] to bootstrap the cluster
49+
remotely:
4350
```console
44-
$ ./contrib/ec2/provision-ec2-controller.sh us-west-2
45-
Creating security group: deis-controller
46-
+ ec2-create-group deis-controller -d 'Created by Deis'
47-
GROUP sg-3c3a1c0c deis-controller Created by Deis
48-
+ set +x
49-
Authorizing TCP ports 22,80,443,514 from 0.0.0.0/0...
50-
+ ec2-authorize deis-controller -P tcp -p 22 -s 0.0.0.0/0
51-
...
52-
ec2-203.0.113.33.us-west-2.compute.amazonaws.com
53-
ec2-203-0-113-33.us-west-2.compute.amazonaws.com Chef Client finished, 74 resources updated
54-
...
55-
Instance ID: i-31c8d106
56-
Flavor: m1.large
57-
Image: ami-72e27c42
58-
Region: us-west-2
59-
Public DNS Name: ec2-203-0-113-33.us-west-2.compute.amazonaws.com
60-
Public IP Address: 203.0.113.33
61-
Run List: recipe[deis::controller]
62-
...
51+
$ export FLEETCTL_TUNNEL=ec2-12-345-678-90.us-west-1.compute.amazonaws.com
52+
$ ./initialize-ec2-cluster.sh
53+
The authenticity of host '54.215.248.50:22' can't be established.
54+
RSA key fingerprint is 86:10:74:b9:6a:ee:3b:21:d0:0f:b4:63:cc:10:64:c9.
55+
Are you sure you want to continue connecting (yes/no)? yes
56+
Warning: Permanently added '54.215.248.50:22' (RSA) to the list of known hosts.
57+
Job deis-registry.service started on aec641dc.../172.31.21.4
58+
Job deis-logger.service started on 494dcb6a.../172.31.5.226
59+
Job deis-database.service started on aec641dc.../172.31.21.4
60+
Job deis-cache.service started on aec641dc.../172.31.21.4
61+
Job deis-controller.service started on aec641dc.../172.31.21.4
62+
Job deis-builder.service started on 494dcb6a.../172.31.5.226
63+
Job deis-router.service started on aec641dc.../172.31.21.4
64+
done!
65+
```
66+
67+
7. After that, wait for the components to come up, check which host the controller is
68+
running on and register with Deis!
69+
```
70+
$ fleetctl list-units
71+
UNIT LOAD ACTIVE SUB DESC MACHINE
72+
deis-builder.service loaded active running deis-builder d9f1f3ea.../172.31.5.62
73+
deis-cache.service loaded active running deis-cache d9f1f3ea.../172.31.5.62
74+
deis-controller.service loaded active running deis-controller d9f1f3ea.../172.31.5.62
75+
deis-database.service loaded active running deis-database 13c5541b.../172.31.5.61
76+
deis-logger.service loaded active running deis-logger d9f1f3ea.../172.31.5.62
77+
deis-registry.service loaded active running deis-registry 4c263e91.../172.31.24.155
78+
deis-router.service loaded active running deis-router 13c5541b.../172.31.5.61
79+
$ deis register ec2-12-345-678-90.us-west-1.compute.amazonaws.com:8000
80+
username: deis
81+
password:
82+
password (confirm):
83+
email: info@opdemand.com
6384
```
6485

65-
[knifec2]: http://docs.opscode.com/plugin_knife_ec2.html
86+
[aws-cli]: https://github.com/aws/aws-cli
87+
[template]: https://s3.amazonaws.com/coreos.com/dist/aws/coreos-alpha.template
88+
[cf-params]: cloudformation-parameters.json
89+
[pro-script]: provision-ec2-cluster.sh
90+
[init-script]: initialize-ec2-cluster.sh

contrib/ec2/cloudformation.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[
2+
{
3+
"ParameterKey": "KeyPair",
4+
"ParameterValue": "deis"
5+
}
6+
]

contrib/ec2/distribute-amis.sh

Lines changed: 0 additions & 20 deletions
This file was deleted.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Usage: ./initialize-ec2-cluster.sh
4+
#
5+
6+
set -e
7+
8+
THIS_DIR=$(cd $(dirname $0); pwd) # absolute path
9+
CONTRIB_DIR=$(dirname $THIS_DIR)
10+
ROOT_DIR=$(dirname $CONTRIB_DIR)
11+
12+
# check for fleetctl in $PATH
13+
if ! which fleetctl > /dev/null; then
14+
echo 'Please install fleetctl and ensure it is in your $PATH.'
15+
echo 'See https://github.com/coreos/fleet for more information'
16+
exit 1
17+
fi
18+
19+
if [ -z "$FLEETCTL_TUNNEL" ]
20+
then
21+
echo 'Please set $FLEETCTL_TUNNEL.'
22+
echo 'See https://github.com/coreos/fleet/blob/master/Documentation/remote-access.md'
23+
exit 1
24+
fi
25+
26+
cd $ROOT_DIR
27+
28+
# upload each component's systemd unit to the fleet cluster
29+
for component in registry logger database cache controller builder router
30+
do
31+
pushd $component/systemd > /dev/null
32+
fleetctl submit deis-$component.service
33+
fleetctl start deis-$component.service
34+
popd > /dev/null
35+
done
36+
37+
echo "done!"

contrib/ec2/prepare-controller-ami.sh

Lines changed: 0 additions & 77 deletions
This file was deleted.

contrib/ec2/prepare-node-ami.sh

Lines changed: 0 additions & 70 deletions
This file was deleted.

0 commit comments

Comments
 (0)