How to set charm constraints within a bundle

To make a bundle as reusable as possible, it’s common to set minimum constraints for its associated charms, much like you would when deploying charms from the command line. This is done by including a constraints field to a charm’s definition.

For example, to add memory and CPU constraints to MySQL:

mysql:
  charm: "cs:mysql-57"
  num_units: 1
  constraints: mem=2G cores=4
  annotations:
    "gui-x": "139"
    "gui-y": "168"

Here we show how to co-locate applications along with constrained LXD containers on a single machine:

applications:
  wordpress:
    charm: "cs:wordpress-5"
    num_units: 1
    constraints: mem=1G cores=1
    annotations:
      "gui-x": "339.5"
      "gui-y": "-171"
    to: lxd:0
  mysql:
    charm: "cs:mysql-57"
    num_units: 1
    constraints: mem=2G cores=2
    annotations:
      "gui-x": "79.5"
      "gui-y": "-142"
    to: lxd:0
relations:
  - - "wordpress:db"
    - "mysql:db"
machines:
  "0":
    series: xenial
    constraints: "arch=amd64 mem=4G cores=4"

Refer to the Using constraints page for in-depth coverage of constraints.


Last updated 11 months ago.