Install LXD
In order to deploy a Charm, we first need to install the Charmed Operator Lifecycle Manager (OLM). To install the OLM, we need to install a package named juju
(which is why the OLM is often called “juju”). But, as its name indicates, the OLM is a lifecycle manager. That means we also need to configure it with something that it can manage. This can be a public cloud, a private cloud, or a virtualization environment. As mentioned above, in this tutorial we will configure it with LXD.
LXD is a very easy to use container management environment. It runs on many different Linux distributions and it can be used even on Mac and Windows.
The first step in setting up LXD is to install it. On Ubuntu, this can be done in one line, via snap
:
$ sudo snap install lxd
…
The second step in setting up LXD is to initialise it. This can be done very easily using the command lxd init. This brings up an interactive mode. For the purpose of this tutorial, for each question you can simply choose the default values:
$ lxd init
Finally, IPv6 needs to be disabled:
lxc network set lxdbr0 ipv6.address none
Do not execute lxd init on a already set up lxd installation. It will likely reset a number of things including setup networking.
Please note that the lxd package also contains lxc:. Lxd is the name for the management software while lxc is the name for the runtime. In fact you will see lxd and lxc in the remainder of the tutorial depending on which of the two is required at a particular step.
Install Juju
The second prerequisite step is to prepare the tool that the charm will be deployed with. This tool is the Charmed Operator Lifecycle Manager (OLM). Preparing the OLM basically entails installing it. More specifically, we will need to install a package named juju
(which is why the OLM is often called “Juju” or “juju”).
Just like LXD, juju is available on a number of Linux distributions, and can be even installed on other OSes And, just like LXD, on Ubuntu it can be installed very easily via snap
:
$ sudo snap install juju --classic
juju 2.9.19 from Canonical✓ installed
After it has been installed, you can verify the installation by using the juju version
command:
$ juju version
Since Juju 2 is being run for the first time, downloaded the latest public cloud information.
2.9.19-ubuntu-amd64
Now you can check what clouds are known out-of-the-box by juju by using the juju clouds
command:
$ juju clouds --all
You can bootstrap a new controller using one of these clouds...
Clouds available on the client:
Cloud Regions Default Type Credentials Source Description
aws 21 us-east-1 ec2 0 public Amazon Web Services
aws-china 2 cn-north-1 ec2 0 public Amazon China
aws-gov 2 us-gov-west-1 ec2 0 public Amazon (USA Government)
azure 40 centralus azure 0 public Microsoft Azure
azure-china 4 chinaeast azure 0 public Microsoft Azure China
cloudsigma 12 dub cloudsigma 0 public CloudSigma Cloud
equinix 25 px equinix 0 public
google 21 us-east1 gce 0 public Google Cloud Platform
localhost 1 localhost lxd 0 built-in LXD Container Hypervisor
oracle 4 us-phoenix-1 oci 0 public Oracle Compute Cloud Service
rackspace 6 dfw rackspace 0 public Rackspace Cloud
For the managed clouds, juju uses a controller and if the default controller initialization for lxd did not perform so far (as it can be seen with the message You can bootstrap...
), you can create a new controller with the juju bootstrap
command.
As with LXD, this will bring up an interactive mode and, for the purpose of this tutorial, it is fine to simply choose at every step the default value:
$ juju bootstrap
Clouds
aws
aws-china
aws-gov
azure
azure-china
cloudsigma
equinix
google
localhost
oracle
rackspace
Select a cloud [localhost]:
Enter a name for the Controller [localhost-localhost]:
Creating Juju controller "localhost-localhost" on localhost/localhost
Looking for packaged Juju agent version 2.9.19 for amd64
Located Juju agent version 2.9.19-ubuntu-amd64 at https://streams.canonical.com/juju/tools/agent/2.9.19/juju-2.9.19-ubuntu-amd64.tgz
To configure your system to better support LXD containers, please see: https://github.com/lxc/lxd/blob/master/doc/production-setup.md
Launching controller instance(s) on localhost/localhost...
- juju-2be1c8-0 (arch=amd64)
Installing Juju agent on bootstrap instance
Fetching Juju Dashboard 0.8.1
Waiting for address
Attempting to connect to 10.199.245.184:22
Connected to 10.199.245.184
Running machine configuration script...
Bootstrap agent now started
Contacting Juju controller at 10.199.245.184 to verify accessibility...
Bootstrap complete, controller "localhost-localhost" is now available
Controller machines are in the "controller" model
Initial model "default" added
You can check again, what juju currently supports. Now, a local cloud on localhost
with type lxd
should be present:
$ juju clouds --all
Clouds available on the controller:
Cloud Regions Default Type
localhost 1 localhost lxd
Clouds available on the client:
Cloud Regions Default Type Credentials Source Description
aws 21 us-east-1 ec2 0 public Amazon Web Services
aws-china 2 cn-north-1 ec2 0 public Amazon China
aws-gov 2 us-gov-west-1 ec2 0 public Amazon (USA Government)
azure 40 centralus azure 0 public Microsoft Azure
azure-china 4 chinaeast azure 0 public Microsoft Azure China
cloudsigma 12 dub cloudsigma 0 public CloudSigma Cloud
equinix 25 px equinix 0 public
google 21 us-east1 gce 0 public Google Cloud Platform
localhost 1 localhost lxd 1 built-in LXD Container Hypervisor
oracle 4 us-phoenix-1 oci 0 public Oracle Compute Cloud Service
rackspace 6 dfw rackspace 0 public Rackspace Cloud
As you can see, the cloud of type lxd is present in the output. Juju will coordinate with lxd for deploying charms and its applications.
Install Charmcraft
This brings us to our third prerequisite for this tutorial, namely, a tool for packaging applications as charms. There are multiple ways one can do this. In this tutorial we will do this in the simplest possible manner, using the Charmed Operator Software Development Kit (SDK), specifically, the tool named charmcraft
: It is used to build and package Charms. Just like LXD and the OLM, on Ubuntu the SDK’s charmcraft
tool can be installed very conveniently via snap:
$ sudo snap install charmcraft --classic
charmcraft 1.2.1 from Canonical✓ installed
Get Erik’s Example Code Base
The last prerequisite is Erik’s git repository with example code. It contains one Charm implementation which will be used further on in this tutorial. For this tutorial it is required to check out this repository. It can be done with using git:
$ git clone https://github.com/erik78se/juju-operators-examples/
Alternatively, you can navigate to the Github repository in the Web browser and download the archive directly from the Web page. Git control is actually not required, thus a plain download works as well.
This is it for prerequisites, all should be set now to start with the tutorial.