Deploying Apps on Public Clouds

Juju allows deploying charm/bundles on different clouds, including public clouds like AWS, Azure, Google.

We explain here how to install Juju and then to use it for deploying applications on the Amazon Web Services cloud.

Install the software

We assume you have a VM running Ubuntu Xenial (16.04), where to install the Juju controller. Follow the steps in the Quick Start Guide on VM if you don’t have one.

For installing Juju on a different platform, see the Getting Started with Juju.

Login to your node and do the following.

Install Juju by doing this:

$ sudo add-apt-repository -u ppa:juju/stable
$ sudo apt install juju

Select the public cloud

You can see which clouds are available by doing:

$ juju clouds

The output should look like this:

Cloud        Regions  Default        Type        Description
aws               12  us-east-1      ec2         Amazon Web Services
aws-china          1  cn-north-1     ec2         Amazon China
aws-gov            1  us-gov-west-1  ec2         Amazon (USA Government)
azure             18  centralus      azure       Microsoft Azure
azure-china        2  chinaeast      azure       Microsoft Azure China
cloudsigma         5  hnl            cloudsigma  CloudSigma Cloud
google             4  us-east1       gce         Google Cloud Platform
joyent             6  eu-ams-1       joyent      Joyent Cloud
rackspace          6  dfw            rackspace   Rackspace Cloud
localhost          1  localhost      lxd         LXD Container Hypervisor

Select the cloud and region where you want to operate:

$ juju set-default-region aws us-east-1

You need to have an account on AWS and obtain the credentials to use for that account. Login to your EC2 Management Console, then select, from your account name on the top menu bar, My Security Credentials, then click on Continue to Security Credentials. Then select Access Keys (Access Key ID and Secret Access Key) and Create New Access Key.

Note the two values Access Key ID and Secret Access key and use them when prompted to set your credentials by doing:

$ juju add-credential aws
Enter credential name: $NAME
Using auth-type "access-key".
Enter access-key:
Enter secret-key:
Credentials added for cloud aws.

You can choose any name for $NAME.

Create a controller

Before you can start deploying applications, Juju needs to create a controller for the AWS cloud. The controller manages the models you create to host the applications. A model groups the VMs that support an application.

The juju bootstrap command is used to create the controller. The command expects a cloud name and region to use:

$ juju bootstrap aws/us-east-1

You can check that the controller has been created:

$ juju controllers

This will return a list of the controllers known to Juju, which at the moment is the one we just created:

Use --refresh flag with this command to see the latest information.

Controller      Model    User   Access     Cloud/Region   Models  Machines    HA  Version
aws-us-east-1*  default  admin  superuser  aws/us-east-1       2         1  none  2.0.2

The following command shows the currently active controller, model, and user:

$ juju whoami

In our example, the output should look like this:

Controller:  aws-us-east-1
Model:       default
User:        admin

Deploy applications

Juju is now ready to deploy applications from among the hundreds included in the Juju charm store.

We will show as an example, how to deploy a MediaWiki site:

$ juju deploy cs:bundle/mediawiki-single

This will fetch a bundle from the Juju store. A bundle is a pre-packaged set of applications, in this case a ‘MediaWiki’ CMS, and a database to run with it. Juju will install both applications and add a relation between them - this is part of the magic of Juju: it isn’t just about deploying software, Juju also knows how to connect it all together.

Installing shouldn’t take long. You can check on how far Juju has got by running the command:

$ juju status

When the applications have been installed, the output of the above command will look something like this:

Model    Controller     Cloud/Region   Version
default  aws-us-east-1  aws/us-east-1  2.0.2

App        Version  Status   Scale  Charm      Store       Rev  OS      Notes
mediawiki           unknown      1  mediawiki  jujucharms    3  ubuntu
mysql               unknown      1  mysql      jujucharms   29  ubuntu

Unit          Workload  Agent  Machine  Public address  Ports   Message
mediawiki/0*  unknown   idle   0        52.54.137.251   80/tcp
mysql/0*      unknown   idle   1        54.242.206.58

Machine  State    DNS            Inst id              Series  AZ
0        started  52.54.137.251  i-0f5dd439179e63af4  trusty  us-east-1a
1        started  54.242.206.58  i-00f1ec62d532cea8d  trusty  us-east-1b

Relation  Provides   Consumes  Type
db        mediawiki  mysql     regular
cluster   mysql      mysql     peer

Expose the Service

In order to make your service publicly accessible, you will have to change the cloud provider firewall settings. You can do this from the CLI, with the command:

$ juju expose mediawiki

Alternatively, this can be done from the Juju GUI, by selecting the application to expose, click on the Expose option and select the check mark to turn it On.

For more details, see Exposing Applications.

Access the Service

From the juju status output, we can see that the IP address for the MediaWiki site we have created is 52.54.137.251. Open a browser and enter that address to see the site.

Note

Note: To remove all the applications in the model you just created, it is often quickest to destroy the model with the command juju destroy-model default and then create a new model, by doing juju add-model default.