Juju: Deploy, Integrate and Scale Services Instantly on Multiple Clouds
It used to be hard to deploy hardware in a data center. The Cloud changed all of this. You are literally minutes away from booting at 100 instances. This, however, has brought other problems. Applications, clusters, software stacks, etc. need to be able to work on many instances that are dynamically scaled up and down. All of them need to be integrated, even if IPs are changing continuously.
The first generation of solutions focused on automating server provisioning. You wrote a receipt of how a web server needed to be provisioned. You then assigned a role to each instance and it would be automatically set up.
The problem is that server provisioning is only part of managing a complete service stack. Different services need to be able to communicate with one another. Services need to be monitored, backed-up, assets managed, “sys-logged”, performance analyzed, etc. Each new element in your stack would need single sign-on and to be integrated with your Nagios, Ganglia, Logstash, etc. Each Service scales differently. Some need a shared file system. Others need a high-availability proxy or database. Yet others rely on P2P broadcasting, which does not natively work in the Cloud.
There is now a second-generation solution that promises to deploy, integrate and scale instantly on all major Public Clouds as well as Private Cloud. Instead of focusing on the servers, it focuses on the services that run on top of these servers. Its name is Juju, which means magic. Juju’s magic is called a Charm. A Charm encapsulates a service. A Charm exposes standardized interfaces towards the embedded service, allowing other Charms to easily integrate. A Charm also scales the embedded service transparently.
To understand the difference between service orchestration and server provisioning let’s look at some Charms. Where service provisioning tools would be just installing WordPress on a virtual server, Juju also does integration. So when the WordPress Charm is integrated with MySQL, automatically all tables and data are created in the database. A Charm also knows about security, so when you expose WordPress to the world, automatically the right ports are opened. When scaling the MySQL Charm, the Charm knows the concept of Multi-Master Cluster and Read Slaves, so you are able to deploy a very complex MySQL cluster instantly.
The Juju Basics
Using Juju is very easy. There are only a handful of commands that you actively use: deploy, add-relation, add-unit, expose.
# Bootstrap the Juju environment according to your preferred configuration, e.g. AWS,
# HP Cloud, Open Stack, Local, etc.
# Deploy mysql and wordpress
juju deploy mysql
juju deploy wordpress
# Create a relationship between wordpress and mysql and
# assures the wordpress schema is installed inside Mysql
juju add-relation wordpress mysql
# Open ports hence wordpress is publicly accessible
juju expose wordpress
Now let’s take it to the next level. We want to go to production with a highly scalable and high available Java application that is fully cached and monitored. We also want to mix public and unofficial/private charms to show you how this is done.
# Create 10 instances of tomcat and link it to mysql. This is an example of using an unofficial/private charm
# Also note that we only create a relation once per service, not per node.
juju deploy -n 10 cs:~robert-ayres/precise/tomcat-3 tomcat
juju add-relation tomcat mysql
# Create a high-available database with three masters in a cluster (by adding two more units to the existing one)
juju add-unit -n 2 mysql
# and add 5 read slaves called slavedb
juju deploy -n 5 mysql slavedb
# create a master-slave relation between the 3 masters and 5 slaves
juju add-relation mysql:master slavedb:slave
# give tomcat access to the read instances
juju add-relation tomcat slavedb
# now let’s add memcached to do some caching
juju deploy memcached
juju add-relation memcached tomcat
# Add HA proxy. On Amazon we could use ELB as well.
juju deploy haproxy
juju add-relation haproxy tomcat
juju expose haproxy
# Now include monitoring, so let’s get Nagios deployed and connected to all services
juju deploy nagios
juju add-relation nagios tomcat
juju add-relation nagios memcached
juju add-relation nagios haproxy
juju add-relation nagios mysql
juju add-relation nagios slavedb
juju expose nagios
# And do some deep logging with a “subordinate” Charm that gets installed on each machine
# Subordinate Charms do not run on a separate machine. NRPE allows to get statistics of
# each machine by running locally, unlike the Nagios Charm that can only test if an interface is up.
juju deploy nrpe
juju add-relation nrpe nagios
juju add-relation nrpe tomcat
juju add-relation nrpe memcached
juju add-relation nrpe haproxy
juju add-relation nrpe mysql
juju add-relation nrpe slavedb
# Want to see the nagios monitoring. Let’s log into the first Nagios machine and
# get the admin password
juju ssh nagios/0 sudo cat /var/lib/juju/nagios.passwd
# Want to know which server nagios runs on. Check all the servers and services:
# Now you can log into Nagios with http://
# Note how all services are being deployed and monitored in Nagios.
# What if I don’t like command lines
juju deploy juju-gui
juju expose juju-gui
So what if I am already using the first generation tools?
Juju is complimentary and provides synergies. A Charm can be written in any language. You can call Puppet modules or Chef recipes from within a Charm. Hence if you have a lot of them, you can reuse them. You can even deploy Puppet or Chef as a Charm.
So what else can you do?
There are many charms. Charms for software development, e.g. Tomcat, Rails/Rack, Node.js, Lamp, Python/Django, etc. For data management, e.g. Hadoop, Hbase, Hive, Cassandra, Mysql, Postgres, Mongo, CouchDB, CouchBase, MemBase, ElasticSearch, Zookeeper, Drupal, WordPress, DokuWiki, Git, etc. For Caching/Proxying/Load-Balancing, e.g. Redis, Memcached, Varnish, Solr, Terracotta, NgInx, HAProxy, Squid, NFS, etc. For monitoring and logging, e.g. Nagios, Logstash, Ganglia, RSyslog, Munin, Kibana, NewRelic, OpenTSDB, etc. And many others, e.g. Puppet, Chef, OpenStack deployment, RabbitMQ, CloudFoundry, Jenkins, OpenERP, etc. Look for official Charms in the Charm Store. But there are also unofficial Charms, e.g. for Amazon ELB, RDS, Route53. You can even use Charms from a private local repository.
But the most important thing is that you can easily write your own Charms and contribute them to the community. If you want to know how Charms work internally see this blog post.
The next steps?
Juju is constantly being extended. New Charms are coming, improvements in the GUI as well as new core functionalities. A shortly to be released feature is a Charm Bundle that will allow you to bundle multiple Charms into one. So if you have a complex Hadoop environment with Hive and HBase, Ganglia, etc. You package it up into a Bundle. You can then also export and import bundles between different environments.
Be sure to check out the Charm Championship because you can earn $10.000 for creating the best Charm Bundles.
You can get more information on installing Juju and any other aspect on the Juju Homepage: juju.ubuntu.com.