Deploying Juju charms¶
This page provides two examples of the deployment of applications (MediaWiki and Moodle) through Juju charms.
Let’s deploy a MediaWiki site. Open a browser and go to the Juju charm store
Type mediawiki on the search box. A list of all the available mediawiki charms appears.
Click on mediawiki-single
Copy the command on the top right box:
$ juju deploy cs:bundle/mediawiki-single
on your Juju client shell.
This will fetch the mediawiki ‘bundle’ from the Juju store. A bundle is a pre-packaged set of applications, and a database to run it with. 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 $CONTROLLER_NAME mycloud/region-ct1-cl1 2.1.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 18.104.22.168 80/tcp mysql/0* unknown idle 1 22.214.171.124 Machine State DNS Inst id Series AZ 0 started 126.96.36.199 9fb19030-b9ec-4bc7-8381-69cfbc5d95ca trusty nova 1 started 188.8.131.52 49836b98-9f19-4e7a-a234-cb3327ad7252 trusty nova Relation Provides Consumes Type db mediawiki mysql regular cluster mysql mysql peer
Logging into the deployed machines¶
You can also log-in to the deploying machine typing:
$ juju ssh mediawiki/0
You will log in as ubuntu user; now type:
$ sudo su -
to become root.
You may now look at the Juju logs, to see how the installation goes on:
$ tail -f /var/log/juju/unit-mediawiki-0.log
Type exit twice to log out from the machine and return to the Juju client.
Expose the service¶
By default the services deployed by Juju are kept behind a firewall. In order to access Mediawiki from the outside world type this command:
$ juju expose mediawiki
This will open the required ports to make the service accessible.
Access the Service¶
From the juju status output, we can see that the IP address for the MediaWiki site we have created is 184.108.40.206. Open a browser and enter that address to see the site.
Adding more services¶
Now suppose that you want to add Nagios service to monitor your application. Following the steps destribed at the beginning of this page go to the Juju store, and search nagios. The most recent version of the charm is for Ubuntu Trusty.
Now suppose that you don’t have enough resources to install the service on a new VM. Let’s then install it on the same machine that hosts the MySQL database! You will have to type this command:
$ juju deploy cs:trusty/nagios-15 --to 1
where 1 is in this case the ID of the machine that hosts MySQL (seen with juju status).
Set a password to Nagios:
$ juju config nagios password=$NAGIOS_PASSWORD
Expose the service:
$ juju expose nagios
You will now see the esposed flag associated to the application:
App Version Status Scale Charm Store Rev OS Notes mediawiki unknown 1 mediawiki jujucharms 3 ubuntu **exposed**
Relate nagios to mediawiki:
$ juju add-relation nagios mediawiki
Once everything is completed juju status will show:
$ juju status Model Controller Cloud/Region Version default $CONTROLLER_NAME mycloud/region-ct1-cl1 2.1.2 App Version Status Scale Charm Store Rev OS Notes mediawiki unknown 1 mediawiki jujucharms 3 ubuntu exposed mysql unknown 1 mysql jujucharms 29 ubuntu nagios unknown 1 nagios jujucharms 15 ubuntu exposed Unit Workload Agent Machine Public address Ports Message mediawiki/0* unknown idle 0 220.127.116.11 80/tcp mysql/0* unknown idle 1 18.104.22.168 nagios/0* unknown idle 1 22.214.171.124 80/tcp Machine State DNS Inst id Series AZ 0 started 126.96.36.199 9fb19030-b9ec-4bc7-8381-69cfbc5d95ca trusty nova 1 started 188.8.131.52 49836b98-9f19-4e7a-a234-cb3327ad7252 trusty nova Relation Provides Consumes Type db mediawiki mysql regular nagios mediawiki nagios regular cluster mysql mysql peer
In this example nagios web server is at 184.108.40.206. Type this address on your browser. When requested type:
Username: nagiosadmin Password: $NAGIOS_PASSWORD
We will here deploy a Moodle application in two ways: at first using a bundle and then through a relation.
First of all, let’s create a model for our test:
$ juju add-model --config config.yaml testmodel $ juju switch testmodel
To deploy the moodle bundle, and then expose it, use the following commands:
$ juju deploy cs:~csd-garr/bundle/moodle-base-1 $ juju expose moodle
This will deploy both the moodle and postgresql applications. The moodle instance should be reachable on the exposed port on the moodle instance IP address.
Now let’s undeploy the applications:
$ juju remove-application postgresql $ juju remove-application moodle
Deploy them again, without using a bundle:
$ juju deploy --series=xenial postgresql $ juju deploy cs:~csd-garr/moodle
And add a relation between postrgresql and moodle:
$ juju add-relation moodle postgresql ERROR ambiguous relation: "moodle postgresql" could refer to "moodle:pgsql-db postgresql:db"; "moodle:pgsql-db po stgresql:db-admin" $ juju add-relation moodle:pgsql-db postgresql:db
Finally, expose the moodle application:
$ juju expose moodle
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.