[Tutorial] Working with storage in Juju to add capacity to OpenStack Swift and PostgreSQL

Juju has the ability to manage virtual machines’ disks and block storage. Using defined storage is a good way to decouple your service’s data from any specific virtual machine. Occasionally, you’ll want to decommission storage, particularly if you’re migrating data.

New to Juju? Click here for a quick introduction.

Juju is a powerful tool, but it can be confusing to know where to start.

Installing Juju

Follow our installation instructions for installation instructions on several operating systems. Once installed, add credentials for your preferred cloud provider.

Juju Terminology

Model
A model represents everything that is sitting behind a digital product. If you are hosting a web application, the model includes the application server, database server(s), firewall rules and virtual machines.

Machine vs Unit
Juju’s documentation uses terms that might mean “virtual machine”, depending on context:

  • a machine is a virtual machine that can be utilised by units
  • a unit represents an application’s link to a machine. Applications are hosted on units. Units have shared access to the machine with other units, although it’s uncommon for a single application to have multiple units on the same machine
  • an instance is used interchangeably with machine; its peer term instance type refer to provider-specific offerings

Storage
Juju uses a single term storage unit to abstract over many offerings provided by cloud providers, including local disks, and block storage.

Container-based deployments

Juju provides first class support container-based workloads via Kubernetes and LXD. For consistency, the project uses the same machines/units terminology.

Create your model

The first thing that we need is a controller. We can create one via the command line. Here we create controller “c-learnjuju” on the AWS region “us-west-2”:

juju bootstrap aws/us-west-2 c-learnjuju 
Creating Juju controller "c-learnjuju" on aws/us-west-2
...

A controller is required because controllers actively manage models. They’re able to monitor your compute resources, such as network and storage, in real time.

Deploy your applications

Now that you have a controller, you can add functionality to your model. We’ll deploy the OpenStack Swift charm with 5x100GB EBS block storage volumes.

juju deploy swift-storage
juju add-storage swift-storage/0 block-devices=ebs,100G,5
added storage block-devices/0 to swift-storage/0
added storage block-devices/1 to swift-storage/0
added storage block-devices/2 to swift-storage/0
added storage block-devices/3 to swift-storage/0
added storage block-devices/4 to swift-storage/0

To allocate storage to PostgreSQL, the syntax is similar.

juju deploy postgresql 
Located charm "cs:postgresql-199".
Deploying charm "cs:postgresql-199".
juju add-storage postgresql/0 pgdata=ebs-ssd,50G,1
added storage pgdata/5 to postgresql/0

The syntax of the add-storage command is fully documented via juju help add-storage in the command line as well as in our online documentation.

Each charm provides a labels for naming purposes. The postgresql charm defines “pgdata”. The swift-storage charm defines “block-devices”.

Providers define the storage types that are available. We’ve used ebs and ebs-ssd in our examples so far.

How to identify what storage your charm supports

Each charm defines storage within its metadata.yaml file. It’s possible to access this from the charm’s page on jaas.ai. Look for the metadata.yaml file in the “Files” box on the right.

If you really prefer the command-line though, you can install the charm-helpers library with pip install charm-helpers. Once that’s installed, you can

charm pull cs:swift-storage-256
cat swift-storage/metadata.yaml
...
storage:
  block-devices:
    type: block
    multiple:
      range: 0-
    minimum-size: 1G
How to identify which storage types your provider supports

Juju has a concept of a “storage pool”. Using the command juju list-storage-pools will show you the pools that are defined for your provider.

Removing storage

Shortcut to remove all storage units of an application

If you are removing an application from a model, you can delete any storage that’s been allocated with the --destroy-storage option to remove-application:

juju remove-application --destroy-storage postgresql
removing application postgresql
- will remove storage pgdata/5

Removing storage units one by one

If you wish to be more precise, Juju offers you the ability to destroy each storage unit individually. Destroying storage takes place in 2 phases. First we detach the storage units from applications, then we remove the storage from the model.

Each storage unit requires an individual command.

juju detach-storage block-devices/0
juju detach-storage block-devices/1
juju detach-storage block-devices/2
juju detach-storage block-devices/3
juju detach-storage block-devices/4
juju remove-storage block-devices/0
juju remove-storage block-devices/1
juju remove-storage block-devices/2
juju remove-storage block-devices/3
juju remove-storage block-devices/4

Cleaning up

To delete everything that Juju has provisioned, issue the destroy-controller command:

juju destroy-controller -y --destroy-storage --destroy-all-models c-learnjuju
Destroying controller
...

Need help?

More detailed information is provided on our documentation site. If anything’s unclear, please ask for clarification in this thread!

3 Likes