Removing Juju objects

This section looks at how to remove the various objects you will encounter as you work with Juju. These are:

  • applications
  • units
  • machines
  • relations

To remove a model or a controller see the Models and Controllers pages respectively.

For guidance on what to do when a removal does not apply cleanly consult the Troubleshooting removals page.

Removing applications

An application can be removed with:

juju remove-application <application-name>

If dynamic storage is in use, the storage will, by default, be detached and left alive in the model. However, the --destroy-storage option can be used to instruct Juju to destroy the storage once detached. See Using Juju Storage for details on dynamic storage.

Note: Removing an application which has active relations with another running application will terminate that relation. Charms are written to handle this, but be aware that the other application may no longer work as expected. To remove relations between deployed applications, see the section below.

Removing units

It is possible to remove individual units instead of the entire application (i.e. all the units):

juju remove-unit postgresql/2

In the case that the removed unit is the only one running the corresponding machine will also be removed unless any of the following is true for that machine:

  • it was created with juju add-machine
  • it is not being used as the only controller
  • it is not hosting Juju-managed containers (KVM guests or LXD containers)

To remove multiple units:

juju remove-unit mediawiki/1 mediawiki/3 mediawiki/5 mysql/2

The --destroy-storage option is available for this command as it is for the remove-application command above.

Removing machines

Juju machines can be removed like this:

juju remove-machine <number>

However, it is not possible to remove a machine which is currently allocated to a unit. If attempted, this message will be emitted:

error: no machines were destroyed: machine 3 has unit "mysql/0" assigned

By default, when a Juju machine is removed, the backing system, typically a cloud instance, is also destroyed. The --keep-instance option overrides this; it allows the instance to be left running.

Removing relations

A relation can be removed easily enough:

juju remove-relation mediawiki mysql

In cases where there is more than one relation between the two applications, it is necessary to specify the interface at least once:

juju remove-relation mediawiki mysql:db

© 2018 Canonical Ltd. Ubuntu and Canonical are registered trademarks of Canonical Ltd.