Faster LXD - juju/juju GitHub Wiki

Here's some tips for those wishing to reduce LXD bootstrap and provisioning times. This is useful when evaluating charms locally or for Juju Core developers QAing their work.

ZFS

LXD is much faster at creating instances when running on ZFS (supported out of the box from Xenial onwards). Run sudo lxd init and ask it to create a ZFS pool for LXD instances.

Package Caching

The Ubuntu squid-deb-proxy package installs the Squid web proxy, configured to cache debs from Ubuntu's software mirrors. Using it can significantly speed up charm deployments.

Use a configuration like this at /etc/squid-deb-proxy/squid-deb-proxy.conf: https://gist.github.com/mjs/bfcea2e87e9a603420d7b32d25704b65

Remember to edit the http_port stanzas at the top to match the addresses you've configured the lxdbr0 network interface to use (via lxd init). If you want the host machine to also be able to use squid-deb-proxy then leave in line for 127.0.0.1.

You'll also want to install rewrite.pl in /etc/squid-deb-proxy/. This is a little Perl program which rewrites requests to the configured Ubuntu mirrors. You can find an appropriate version here: https://gist.github.com/mjs/90ac9f9d3dde4f511f02c0c4cbc4da00

Remember to update the mirror to suit your location.

Once the configuration is ready, restart squid-deb-proxy like this:

sudo service squid-deb-proxy restart

Juju APT proxy config

In order to get Juju to use squid-deb-proxy you'll need to pass configuration like this to any bootstrap and add-model commands:

apt-http-proxy: http://10.0.8.1:8888

Remember to change the address and port to match what squid-deb-proxy is configured to listen on.

APT proxy config for the host

In order to have the host machine also use squid-deb-proxy (so that it benefits from any package downloads done inside containers and vice versa), drop a file like this into /etc/apt/apt.conf.d/20proxy:

Acquire::http::Proxy "http://127.0.0.1:8888";

Again, remember to adjust the port to the one that squid-deb-proxy is using.

Turn off automatic package upgrades

By default Juju will run apt-get upgrade on machines it creates. While this is useful in production scenarios, it isn't usually necessary for test deployments. Turning it off can greatly speed up deployments.

The relevant Juju configuration for this is:

enable-os-upgrade: false

Note that there is also a enable-os-refresh-update option which you might be tempted to disable but I've found this normally causes more problems than it's worth (charms fail to install).

Suggested Juju config for LXD deployments

Here's a complete suggested configuration for test LXD deployments that takes into account the ideas discussed in this article (as well as turning on DEBUG logging):

default-series: xenial
logging-config: "<root>=DEBUG"
apt-http-proxy: http://10.0.8.1:8888
enable-os-refresh-update: true
enable-os-upgrade: false

You can keep this in a file and pass it as the --config option to juju bootstrap and juju add-model but a more convenient approach is to create a custom LXD cloud with these options set. A section like this in ~/.local/share/juju/clouds.yaml will define a LXD cloud called "dev":

clouds:
  dev:
    type: lxd
    config:
      apt-http-proxy: http://10.0.8.1:8888
      default-series: xenial
      enable-os-refresh-update: true
      enable-os-upgrade: false
      logging-config: <root>=DEBUG

This can then be used like this:

juju bootstrap foo dev

This is somewhat easier than having to remember to add --config to the bootstrap and add-model commands.

⚠️ **GitHub.com Fallback** ⚠️