I have been looking into differnet in-house PaaS solutions lately. I´ll leave the reasons for choosing PaaS and the wider evaluation to a later post. I´ll just quickly update a little bit about background in between. So this is my experience setting up CloudFoundry on AWS. This is v1 of CloudFoundry.
Note: After writing up most of this stuff I also discovered this setup http://cloudfoundry.github.io/docs/running/deploying-cf/ec2/ . It seems to me that it is for the v2 setup. You might want to check that.
Update: While this stuff works for the basic setup, I have experienced some real issues with getting Postgres running as a service. So as I say in the end here; this is a good way to get something up and running to experiment. But don´t expect this to be something ready for production. You will probably need to fork the Git repo and fix some issues for that to work. I am moving on to v2 (supposed to be released in April), hoping Dr. Nic’s superb tooling will be available there soon.
CloudFoundry is the Open Source PaaS backed by VMWare. It uses BOSH as a sort of release management and packaging system. You can read a little more about it here. Chef recipes to set up CF without BOSH is also available, but I have not tested those.
The reason I have had some problems getting this to work is because CloudFoundry is currently in the middle of a big refactoring for V2. That means that there are many parts in movement, and the reason I have to take certain steps is that I want to deploy the stable V1 version.
- Some parts does not support a different region that the default. I will describe how to handle this, but when choosing AWS regions, just going with the default will keep things easier.
- You need a DNS wildcard setup. You will need control of a DNS record and if you do this early in the process you won´t have to wait for DNS to propagate changes.
Disclaimer: Parts of this is just a duplication of what is available at the resources over. I include them here to make sure it is something that can be followed easily. They might change outside this document.
Set up DNS
To enable communication with your CloudFoundry you will have to configure DNS with a wildcard. You can provision the IP from Amazon automatically with the script later (it will prompt you), but doing this now will save some time later as DNS changes take some time to propagate.
- Enter AWS EC2 console
- Make sure you have chosen the region you will be deploying to
- Click Elastic IPs in the menu to the left
- Click Allocate new address
Then login to your DNS registrar and map a subdomain with wildcard to this address. It would look something like this: *.cloudfoundry.mydomain.com 232.234.423.64 (The IP here is of course the one you allocated in AWS under Elastic IPs)
Install the gems needed
gem install bosh-bootstrap
Bootstrap BOSH and Micro BOSH
bosh-bootstrap deploy && bosh-bootstrap ssh
Answer the questions and wait. 🙂
Download CloudFoundry and package a release
After that is done you will be logged in to the Bosh server at the prompt. Take the command line below, change the necessary settings and run it.
git config --global user.email "firstname.lastname@example.org" && git config --global user.name "My Name" && sudo gem install bosh-cloudfoundry && export TMPDIR=/var/vcap/store/tmp
Now run the preparation:
bosh cf prepare system production --core-ip 232.234.423.64 --root-dns cloudfoundry.mydomain.com --core-server-flavor m1.large
What has just happened is that BOSH has downloaded and packaged the CloudFoundry release so that it can be deployed. Sadly, it is not the correct release. 🙂 So we delete that:
bosh delete release appcloud-master
Then we need to package the release we want to deploy:
bosh cf upload release --branch v1
Some manual corrections
Alright, things are looking good so far. Before we deploy further we need to do the following:
- Reduce the number of nodes used for compiling the release. See this bug as to why.
- Add region information to the system description if we are using a non-default region. See this bug for a description.
Reduce compile nodes
Edit the /var/vcap/store/systems/production/deployments/production-core.yml file. Find the compile section and change the number to 4. It should look like this:
Find the parts containing cloud_properties (there are usually two places) in /var/vcap/store/systems/production/deployments/production-core.yml and add extra lines. It should now look like this:
Deploy the release
Ready to deploy into a system:
bosh cf deploy
Congratulations! You should now be able to run on your very own PaaS Cloud. Take note of the username and password at the end of the output:
vmc target http://api.cloudfoundry.mydomain.com
Setting target to http://api.cloudfoundry.mydomain.com... OK
vmc register email@example.com --password 5a93f82 --verify 5a93f82
Your password strength is: strong
Creating user... OK
Because of some missing feature in the v1 branch there are some incorrect paths. From the Bosh controller (where you´ve done everything else) do:
bosh ssh core/0
su - vcap
The default password for vcap is c1oudc0w . Pretty insecure as this is public knowledge. Now might be a good time to change that. 😉 Then do:
sudo mkdir -p /var/vcap/shared && sudo chown vcap:vcap /var/vcap/* -R
Using the cloud
To activate running on cloud on your own machine with:
vmc target http://api.cloudfoundry.mydomain.com
The username and password can be found in the output from deploy. See above for an example.
One step further
This is really optional, but lets your experiment a but more with scaling and services. A couple of notes:
- The bosh cf plugin rewrites the config yaml file for each run, so stuff you have fixed manually like size of compile cluster and cloud_properties with zone info will need to be changed again.
- The security groups setup in Amazon is lacking when you scale into more nodes. You will have to make a manual change here before proceeding.
Fixing the security group
The problem is that the security group blocks some communication between the nodes. I have opened everything between the nodes which might be too much. But it works. 🙂
- Login to the Amazon AWS EC2 console
- Click security groups
- Click on the cloudfoundry-production group
- Add a rule enabling ports 0-65535 from cloudfoundry-production (start typing that name in source and you will get auto-complete)
Handling the rewrite yaml file issue
Just after doing the first deploy I copy a version of production-core.yml to my home folder. I can then do diffing agains any updated file by the plugin to see what has been added and removed. Through some manual labour I can transfer the settings back. For now. 🙂
Help I´ve messed up!
Ooooh, you poor bastard. 😉 This really requires a bit of understanding of how BOSH works, but you could try one of the following:
bosh delete deployment production-core && bosh cf deploy
Some final notes
Warning: This is a dev setup. How to switch to a production setup I havn´t quite figured yet, or what that actually means. There are also lots of default passwords here, so it´s pretty bad from a security point. Use with caution. 🙂 It is a nice starting point for experimenting though.
CloudFoundry looks like it´s taking a good direction so it will be very interesting to follow the further development. Thanks to an active Open Source community around it you can get answers to your questions, and also find tools like the bosh-bootstrap and bosh-cf-plugin that is used in the recipe created by the always helpful Dr. Nic at Stark & Wayne.
I might give the v2 setup (link at the start of the document) a stab later on.
Let me know if you have any questions, and check Github issues and the mailing list. 🙂