How to manage constraints
Setting constraints for a controller
Constraints are applied to the controller during its creation using the
juju bootstrap --bootstrap-constraints cores=2 google
Here, we want to ensure that the controller has at least two CPUs.
See Creating a controller for details and further examples.
Constraints applied with ‘–bootstrap-constraints’ will automatically apply to any future controllers provisioned for high availability. See Controller high availability.
Setting constraints for the initial
Constraints can be applied to every machine (controller and non-controller) in the ‘controller’ and ‘default’ models. This is done, again, during the controller-creation process, but by using the
--constraints option instead:
juju bootstrap --constraints mem=4G aws
See Creating a controller for more guidance.
Individual constraints from
--bootstrap-constraints override any identical constraints from
--constraints if these options are used in combination.
For the LXD cloud, the following invocation will place a limit of 2GiB of memory for each machine:
juju bootstrap --constraints mem=2G localhost
Setting and displaying constraints for a model
A model’s constraints—which will also affect any subsequent machines in that model—are set with the
juju set-model-constraints mem=4G
For the LXD cloud, all new machines in the current model will be limited to an instance type of ‘c5.large’ (2 CPU and 4 GiB):
juju set-model-constraints instance-type=c5.xlarge
A model’s constraints are displayed with the
A model’s constraints can be reset by leaving the value part empty :
juju set-model-constraints mem=
Setting, displaying, and updating constraints for an application
Constraints at the application level can be set at deploy time, via the
deploy command. To deploy the
mariadb charm to a machine that has at least 4 GiB of memory:
juju deploy mariadb --constraints mem=4G
To deploy MySQL on a machine that has at least 6 GiB of memory and 2 CPUs:
juju deploy mysql --constraints "mem=6G cores=2"
Multiple constraints are space-separated and placed within quotation marks.
To deploy Apache while ensuring its machine will have 4 GiB of memory (or more) as well as ignoring a possible
cores constraint (previously set at either the model or application level):
juju deploy apache2 --constraints "mem=4G cores="
For the LXD cloud, we deploy PostgreSQL using a combination of an instance type and a specific CPU constraint. Below, instance type
c5.large maps to 2 CPUs and 4 GiB, but the specific memory constraint of 3.5 GiB yields a machine with 2 CPUs and 3.5 GiB of memory:
juju deploy postgresql --constraints "instance-type=c5.large mem=3.5G"
To deploy Zookeeper to a new LXD container (on a new machine) limited to 5 GiB of memory and 2 CPUs, execute:
juju deploy zookeeper --constraints "mem=5G cores=2" --to lxd
To deploy two units of Redis across two AWS availability zones, run:
juju deploy redis -n 2 --constraints zones=us-east-1a,us-east-1d
An application’s current constraints are displayed with the
juju get-constraints mariadb
An application’s constraints are updated, thereby affecting any additional units, with the
juju set-constraints mariadb cores=2
An application’s default cannot be set until the application has been deployed.
set-constraints commands work with application custom names. See Deploying applications for how to set a custom name.
Setting constraints when adding a machine
Constraints at the machine level can be set when adding a machine with the
add-machine command. Doing so provides a way to override defaults at the all-units, application, model, and all-models levels.
Once such a machine has been provisioned, it can be used for an initial deployment (
deploy) or a scale-out deployment (
add-unit). See Deploying to specific machines for the command syntax to use.
A machine with a constraint can be added in this way:
juju add-machine --constraints arch=arm
To add a machine that is connected to a space, for example
juju add-machine --constraints spaces=storage
If a space constraint is prefixed by ‘^’, then the machine will not be connected to that space. For example, the command below will result in an instance that is connected to both the
internal spaces but not connected to either the
See the network spaces page for details on spaces.
For a LXD cloud, to create a machine limited to two CPUs:
juju add-machine --constraints cores=2
To add eight Xenial machines such that they are evenly distributed among four availability zones:
juju add-machine -n 8 --series xenial --constraints zones=us-east-1a,us-east-1b,us-east-1c,us-east-1d
Last updated 11 days ago.