How to manage units

See also: Unit

This document demonstrates various operations that you can perform on a unit.

Units are also relevant when adding storage or scaling an application. See How to manage storage and How to manage applications.

Contents:

Add a unit

See also: juju add-unit

To add a unit, use the add-unit command followed by the application name:

juju add-unit mysql

By using various command options, you can also specify the number of units, the model, the kind of storage, the target machine, etc.

Show details about a unit

See also: juju show-unit

To see more details about a unit, use the show-unit command followed by the unit name:

juju show-unit mysql/0

By using various options you can also choose to get just a subset of the output, a different output format, etc.

List a unit’s resources

See also: juju resources

To see the resources for a unit, use the resources command followed by the unit name. For example:

juju resources mysql/0

Show the status of a unit

See also: juju status

To see the status of a unit, use the status command:

juju status

This will show information about the model, along with its machines, applications and units. For example:

Model           Controller           Cloud/Region        Version  SLA          Timestamp
tutorial-model  tutorial-controller  microk8s/localhost  2.9.34   unsupported  12:10:16+02:00

App             Version                         Status  Scale  Charm           Channel  Rev  Address         Exposed  Message
mattermost-k8s  .../mattermost:v6.6.0-20.04...  active      1  mattermost-k8s  stable    21  10.152.183.185  no       
postgresql-k8s  .../postgresql@ed0e37f          active      1  postgresql-k8s  stable     4                  no       Pod configured

Unit               Workload  Agent  Address       Ports     Message
mattermost-k8s/0*  active    idle   10.1.179.151  8065/TCP  
postgresql-k8s/0*  active    idle   10.1.179.149  5432/TCP  Pod configured

Set the meter status on a unit

See also: juju set-meter-status

To set the meter status on a unit, use the set-meter-status command followed by the unit name. For example:

juju set-meter-status myapp/0

Mark unit errors as resolved

See also: juju resolved

To mark unit errors as resolved, use the resolved command followed by the unit name or a list of space-separated unit names. For example:

juju resolved myapp/0

Remove a unit

See also: juju remove-unit, Removing things reference

To remove individual units instead of the entire application (i.e. all the units), use the remove-unit command followed by the unit name. For example, the code below removes unit 2 of the PostgreSQL charm.

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)

It is also possible to remove multiple units at a time by passing instead a space-separated list of unit names:

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

To also destroy the storage attached to the units, add the --destroy-storage option.

As a last resort, use the --force option (in v.2.6.1).