Blog

Deploying a Node.js app to Docker on CoreOS using Deis

18 Jun, 2014
Xebia Background Header Wave

The world of on-premise private PaaSes is changing rapidly. A few years ago, we were building on on-premise private PaaSes based upon the existing infrastructure and using Puppet as an automation tool to quickly provision new application servers.  We provided a self-service portal where development teams could get any type of server in any type of environment running within minutes.  We created a virtual server for each application to keep it manageable, which of course is quite resource intensive.
Since June 9th, Docker has been declared production ready, so this opens  the option of provisioning light weight containers to the teams instead of full virtual machine. This will increase the speed of provisioning even further while reducing the cost of creating a platform and minimising resource consumption.
To illustrate how easy life is becoming, we are going to deploy an original CloudFoundry node.js application to Docker on a CoreOS cluster. This hands-on experiment is based on MacOS, Vagrant and VirtualBox.

Step 1. Installing  etcdctl and fleetctl

Before you start, you need to install etcdctl and fleetctl on your host.  etcd is a nifty distributed key-value store while fleet manages the deployment of  (Docker) services to a CoreOS cluster.
$ brew install go etcdctl
$ git clone <a href="https://github.com/coreos/fleet.git">https://github.com/coreos/fleet.git</a>
$ cd fleet && ./build && mv bin/fleetctl /usr/local/bin

Step 2. Install the Deis Command Line Client

To control the PaaS you need to install the Deis command line client:
$ brew install python
$ sudo pip install deis

Step 3. Build the platform

Deis  provides all the facilities for building, deployment and managing applications.
$ git clone <a href="https://github.com/deis/deis.git">https://github.com/deis/deis.git</a>
$ cd deis
$ vagrant up

$ ssh-add ~/.vagrant.d/insecure_private_key
$ export DOCKER_HOST=tcp://172.17.8.100:4243
$ export FLEETCTL_TUNNEL=172.17.8.100
$ make pull

Step 4. Start the platform

Now all is set to start the platform:
$ make run
After this run has completed, you can see that the 7 components in the Deis Architecture have been started using the list-units command: The builder, the cache, the controller, the database, the logger, the registry and the router. This architecture looks quite similar to the architecture of CloudFoundry.
$ fleetctl list-units

UNITSTATELOADACTIVESUBDESCMACHINE
deis-builder.servicelaunchedloadedactiverunningdeis-builder79874bde…/172.17.8.100
deis-cache.servicelaunchedloadedactiverunningdeis-cache79874bde…/172.17.8.100
deis-controller.servicelaunchedloadedactiverunningdeis-controller79874bde…/172.17.8.100
deis-database.servicelaunchedloadedactiverunningdeis-database79874bde…/172.17.8.100
deis-logger.servicelaunchedloadedactiverunningdeis-logger79874bde…/172.17.8.100
deis-registry.servicelaunchedloadedactiverunningdeis-registry79874bde…/172.17.8.100
deis-router.1.servicelaunchedloadedactiverunningdeis-router79874bde…/172.17.8.100

Alternatively, you can inspect the result by looking inside the virtual machine:
$ vagrant ssh -c "docker ps"
Now we have our platform running, we can start using it!

Step 5. Register a new user to Deis and add the public ssh key

$ deis register 172.17.8.100:8000 \
--username=mark \
--password=goddesses \
--email=mark.van.holsteijn@..com
$ deis keys:add ~/.ssh/id_rsa.pub

Step 6. Create a Cluster

Create a application cluster under the domain ‘dev.172.17.8.100.xip.io’.  The –hosts specifies all hosts in the cluster: the only available host  at this moment in the cluster is 172.17.8.100.
$ deis clusters:create dev  dev.172.17.8.100.xip.io \
--hosts=172.17.8.100 \
--auth=~/.vagrant.d/insecure_private_key

Step 7. Get the app

We created a simple but effective  node.js application that show you what happens when you scale or push a new version of the application.
$ git clone git@github.com:mvanholsteijn/sample_nodejs_cf.git
$ deis apps:create appmon --cluster=dev
$ deis config:set RELEASE=deis-v1
$ git push deis master

Step 8. open your application

Voila! Your application is running. Now click on start monitoring.
$ deis apps:open 
you should see something like this:

app-mon-1

Step 9. scaling your application

To see scaling in action,  type the following command:
$ deis ps:scale web=4
It will start 3 new containers which will show up in the list.
app-mon-4

Step 10. upgrading your application

Now make a change to the application, for instance change the message to ‘Greetings from Deis release’ and push your change:
$ git commit -a -m "Message changed"
$ git  push deis master

After a while you will see the following on your monitor!
app-mon-8

Step 11. Looking on CoreOS

You can use  fleetctl again to look at the new services that have been added to the platform!

$ fleetctl list-units

UNITSTATELOADACTIVESUBDESCMACHINE
app-mon_v7.web.1-announce.servicelaunchedloadedactiverunningapp-mon_v7.web.1 announce79874bde…/172.17.8.100
app-mon_v7.web.1-log.servicelaunchedloadedactiverunningapp-mon_v7.web.1 log79874bde…/172.17.8.100
app-mon_v7.web.1.servicelaunchedloadedactiverunningapp-mon_v7.web.179874bde…/172.17.8.100
app-mon_v7.web.2-announce.servicelaunchedloadedactiverunningapp-mon_v7.web.2 announce79874bde…/172.17.8.100
app-mon_v7.web.2-log.servicelaunchedloadedactiverunningapp-mon_v7.web.2 log79874bde…/172.17.8.100
app-mon_v7.web.2.servicelaunchedloadedactiverunningapp-mon_v7.web.279874bde…/172.17.8.100
app-mon_v7.web.3-announce.servicelaunchedloadedactiverunningapp-mon_v7.web.3 announce79874bde…/172.17.8.100
app-mon_v7.web.3-log.servicelaunchedloadedactiverunningapp-mon_v7.web.3 log79874bde…/172.17.8.100
app-mon_v7.web.3.servicelaunchedloadedactiverunningapp-mon_v7.web.379874bde…/172.17.8.100
app-mon_v7.web.4-announce.servicelaunchedloadedactiverunningapp-mon_v7.web.4 announce79874bde…/172.17.8.100
app-mon_v7.web.4-log.servicelaunchedloadedactiverunningapp-mon_v7.web.4 log79874bde…/172.17.8.100
app-mon_v7.web.4.servicelaunchedloadedactiverunningapp-mon_v7.web.479874bde…/172.17.8.100
deis-builder.servicelaunchedloadedactiverunningdeis-builder79874bde…/172.17.8.100
deis-cache.servicelaunchedloadedactiverunningdeis-cache79874bde…/172.17.8.100
deis-controller.servicelaunchedloadedactiverunningdeis-controller79874bde…/172.17.8.100
deis-database.servicelaunchedloadedactiverunningdeis-database79874bde…/172.17.8.100
deis-logger.servicelaunchedloadedactiverunningdeis-logger79874bde…/172.17.8.100
deis-registry.servicelaunchedloadedactiverunningdeis-registry79874bde…/172.17.8.100
deis-router.1.servicelaunchedloadedactiverunningdeis-router79874bde…/172.17.8.100

 

Conclusion

Deis is a very simple and easy to use way to create a PaaS using Docker and CoreOS. The node.js application we created, could be deployed using Deis without a single modification. We will be diving into Deis and CoreOS in more details in following posts!

Mark van Holsteijn
Mark van Holsteijn is a senior software systems architect at Xebia Cloud-native solutions. He is passionate about removing waste in the software delivery process and keeping things clear and simple.
Questions?

Get in touch with us to learn more about the subject and related solutions

Explore related posts