Installing Juju a service orchestration framework

Up to now in this chapter, we have learned about virtualization and OpenStack for deploying and managing virtual servers. Now, it's time to look at a service-modeling tool, Juju. Juju is a service-modeling tool for Ubuntu. Connect it to any cloud service, model your application, and press deploy—done. Juju takes care of lower-level configuration, deployments, and scaling, and even monitors your services.

Juju is an open source tool that offers a GUI and command-line interface for modeling your service. Applications are generally deployed as collections of multiple services. For example, to deploy WordPress, you need a web server, a database system, and perhaps a load balancer. Service modeling refers to the relations between these services. Services are defined with the help of charms, which are collections of configurations and deployment instructions, such as dependencies and resource requirements. The Juju store provides more than 300 predefined and ready-to-use charms.

Once you model your application with the required charms and their relationships, these models can be stored as a bundle. A bundle represents a set of charms, their configurations, and their relationships with each other. The entire bundle can be deployed to a cloud or local system with a single command. Also, similar to charms, bundles can be shared and are available on the Juju store.

This recipe covers the installation of Juju on Ubuntu Server. With the release of Xenial, the latest Ubuntu release, Canonical has also updated the Juju platform to version 2.0.

Getting ready

You need access to the root account or an account with sudo privileges.

Make sure you have the SSH keys generated with your user account. You can generate a new key pair with the following command:

$ ssh-keygen -t rsa -b 2048

How to do it…

Juju 2.0 is available in the Ubuntu Xenial repository, so installation is quite easy. Follow these steps to install Juju, along with LXD for local deployments:

  1. Install Juju, along with the LXD and ZFSUtils packages. On Ubuntu 16, LXD should already be installed:
    $ sudo apt-get update
    $ sudo apt-get install juju-2.0 lxd zfsutils-linux
    
  2. The LXD installation creates a new group, lxd, and adds the current user to it. Update your group membership with newgrp so that you don't need to log out and log back in:
    $ newgrp lxd
    
  3. Now, we need to initialize LXD before using it with Juju. We will create a new ZFS pool for LXD and configure a local lxd bridge for container networking with NAT enabled:
    $ sudo lxd init
    Name of the storage backend to use (dir or zfs): zfs
    Create a new ZFS pool (yes/no)? yes
    Name of the new ZFS pool: lxdpool
    Would you like to use an existing block device (yes/no)? no
    Size in GB of the new loop device (1GB minimum): 20
    Would you like LXD to be available over the network (yes/no)? no
    Do you want to configure the LXD bridge (yes/no)? yes
    

    LXD has been successfully configured.

  4. Now that LXD has been configured, we can bootstrap Juju and create a controller node. The following command will bootstrap Juju with LXD for local deployments:
    $ juju bootstrap juju-controller lxd
    

    This command should take some time to finish as it needs to fetch the container image and the install Juju tools inside the container.

  5. Once the bootstrap process completes, you can check the list of controllers, as follows:
    $ juju list-controllers
    CONTROLLER              MODEL    USER         SERVER
    local.juju-controller*  default  admin@local  10.155.16.114:17070
    
  6. You can also check the LXD container created by Juju using the lxc list command:
    $ lxc list
    
  7. From Juju 2.0 onwards, every controller will install the Juju GUI by default. This is a web application to manage the controller and its models. The following command will give you the URL of the Juju GUI:
    $ juju gui
    ...
    https://10.201.217.65:17070/gui/2331544b-1e16-49ba-8ac7-2f13ea147497/
    ...
    
  8. You may need to use port forwarding to access the web console. Use the following command to quickly set up iptables forwarding:
    $ sudo iptables -t nat -A PREROUTING -p tcp --dport 17070 -j DNAT 
    --to-destination 10.201.217.65:17070
    
  9. You will also need a username and password to log in to the GUI. To get these details, use the following command:
    $ juju show-controller --show-passwords juju-controller
    ...
    accounts:
        admin@local:
          user: admin@local
          password: 8fcb8aca6e22728c6ac59b7cba322f39
    

    When you log in to the web console, it should look something like this:

    How to do it…

    Now, you are ready to use Juju and deploy your applications either with a command line or from the web console.

How it works…

Here, we installed and configured the Juju framework with LXD as a local deployment backend. Juju is a service-modeling framework that makes it easy to compose and deploy an entire application with just a few commands. Now, we have installed and bootstrapped Juju. The bootstrap process creates a controller node on a selected cloud; in our case, it is LXD. The command provides various optional arguments to configure controller machines, as well as pass the credentials to the bootstrap process. Check out the bootstrap help menu with the juju bootstrap --help command.

We have used LXD as a local provider, which does not need any special credentials to connect and create new nodes. When using pubic cloud providers or your own cloud, you will need to provide your username and password or access keys. This can be done with the help of the add-credentials <cloud> command. All added credentials are stored in a plaintext file: ~/.local/share/juju/credentials.yaml. You can view a list of available cloud credentials with the juju list-credentials command.

The controller node is a special machine created by Juju to host and manage data and models related to an environment. The container node hosts two models, namely admin and default, and the admin model runs the Juju API server and database system. Juju can use multiple cloud systems simultaneously, and each cloud can have its own controller node.

From version 2.0 onwards, every controller node installs the Juju GUI application by default. The Juju GUI is a web application that provides an easy-to-use visual interface to create and manage various Juju entities. With its simple interface, you can easily create new models, import charms, and set up relations between them. The GUI is still available as a separate charm and can be deployed separately to any machine in a Juju environment. The command-line tools are more than enough to operate Juju, and it is possible to skip the installation of the GUI component using the --no-gui option with the bootstrap command.

There's more…

In the previous example, we used LXD as a local deployment backend for Juju. With LXD, Juju can quickly create new containers to deploy applications. Along with LXD, Juju supports various other cloud providers. You can get a full list of supported cloud providers with the list-clouds option:

$ juju list-clouds

Juju also provides the option to fetch updates to a supported cloud list. With the update-clouds subcommand, you can update your local cloud with the latest developments from Juju.

Along with public clouds, Juju also supports OpenStack deployments and MaaS-based infrastructures. You can also create your own cloud configuration and add it to Juju with the juju add-cloud command. Like with LXD, you can use virtual machines or even physical machines for Juju-based deployments. As far as you can access the machine with SSH, you can use it with Juju. Check out the cloud-configuration manual for more details: https://jujucharms.com/docs/devel/clouds-manual

See also

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset