Using JAAS to Deploy LXD Containers to Virtualbox VMS on OS X
Canonical has a new service out called JAAS (Juju as a service), more information on JAAS here. In short, JAAS helps ease the process of deploying and maintaining multi-vendor production workloads at scale, and can also be used to facilitate the developer workflow as I will detail below.
I’ve recently found myself using JAAS for a lot of 1-off solutions that probably aren’t exactly *supported* use cases, but JAAS keeps popping up as what seems to be the simplest and most fitting solution so I’ve been going with it.
One such use case for JAAS is the “localhost dev” use case.
Using JAAS, developing Juju deployed applications on OS X couldn’t get easier!
I’ll give a quick overview here with a few steps that will get you up and running in a matter of minutes.
The setup workflow is as follows:
- Add a new JAAS model
- Add the Virtualbox vm to the model
- Deploy lxd-proxy to the vm using Juju
- Deploy an application to a lxd container on the vm
- Use the lxd-proxy “forward-traffic” action to add a PREROUTING rule to reach the application running on the lxd container through the VM from the OS X host
So long as you are registered with JAAS, and have an Ubuntu 16.04 or later virtual machine running on your localhost that you can ssh into, you should be ready to get up and running with the following commands. For the purpose of this example we will use the lxd-proxy charm which can be found in the charmstore here (lxd-proxy layer can be found on github here).
$ juju add-model local-dev-osx aws/us-east-1$ juju add-machine ssh:myuser@myvirtualboxvmip #(gets machine # 0)$ juju deploy ubuntu vbox-host --to 0$ juju deploy cs:~jamesbeedy/lxd-proxy-9$ juju add-relation vbox-host lxd-proxy# Deploy any application to LXD on the virtual machine
$ juju deploy elasticsearch --to lxd:0 #(gets ip 10.0.0.119 on port 9200)# Forward the traffic from port 9000 on the vbox
# vm to port 9200 on the elasticsearch LXD container
$ juju run-action lxd-proxy/0 forward-traffic \
source-port=9000 dest-port=9200 host=10.0.0.119
Now you can connect to the elasticsearch LXD via the local ip address of the virtualbox vm on port 9000. WOOHOO!
Moreover, this workflow is most useful when you need to iterate locally on Juju deployed applications. With a few slight modifications, you can make this paint for any picture by proxying to your own applications.
Lastly, JAAS is not a requirement here. This same process can be preformed using your own Juju controllers!