On Virtualbox, we go to File > Preferences > Network and add a new Host-Only Network and configure DHCP for it.
Then on each VM > Settings > Network you’ll want to set a new Host-Only adapter and select the network you just created.
Once we’re done installing Ubuntu, inside the VM we want to check the adapter names and verify that the second adapter (enp0s3) does not have an IP attached yet. We check the interfaces configuration with:
After that, we edit the interfaces the VM has configured and add the secondary network interface with the name of the second adapter so it looks like this.
After that our adapter should have an IP attached to it.
We repeat the steps for the other guest VMs and you can verify connectivity by pinging each other.
Create two virtual Linux machines and run them with an appropriate hypervisor.
Set up and configure a Linux container in one of the machines.
Manage the container with LXC and LXD. Demonstrate how to migrate it live from the first to the second virtual machine so that it keeps running there and the first machine can be shut down.
Discuss some of the tools such as Virt-Manager to manage virtual machines and containers.
Create our VMs on our Hypervisor
Set the Virtual Network
Set the VN interfaces on VM1, VM2
Set up LXD on VM1, VM2
Create our container on VM1
Create a migration profile on VM1, VM2
Migrate our container
Running Windows 10 on my computer, I installed two Ubuntu Server 16.04 VMs over Virtualbox (I used this hypervisor given my previous experience with it while developping Android applications).
Setting the Virtual Network
Before you install Ubuntu in your VMs, make sure you first set up the internal network for the VMs in VirtualBox, the process of how we did that is explained here Setting a Virtual Network in VirtualBox.
Now we can proceed to install LXD and configure it to make our live migration possible.
Once you have your VM installed and configured, to set up LXD you have execute the following:
sudo apt install lxd
LXD supports a number of storage backends which should be considered in case we wanted to move containers or images in the future between backends. We’ll configure ZFS as it supports all the features LXD needs to offer the fastest and most reliable container experience.
sudo apt install zfsutils-linux
To configure LXD to use it, simply run (do not set proxy nor bridging configuration):
sudo lxd init
Once you’ve got LXD set, we need to sort out the network configuration since LXD doesn’t listen to the network by default. The only way to talk to it is over a local unix socket at /var/lib/lxd/unix.socket.
To have it listen to the network, there are two useful keys to set:
lxc config set core.https_address[::]
lxc config set core.trust_password some-secret-string
It’s also good to set the configuration for the image management on LXD:
LXD does dynamic image caching. When instructed to create a container from a remote image, it will download that image into its image store, mark it as cached and record its origin. After a number of days without seeing any use (10 by default), the image is automatically removed. Every few hours (6 by default), LXD also goes looking for a newer version of the image and updates its local copy.
lxc config setimages.remote_cache_expiry5
lxc config set images.auto_update_interval24
lxc config set images.auto_update_cached false
We repeat these steps for the second VM and at this point we should have a working version of the latest LXD release on both VMs.
Migrating a Container
On the VM we want to migrate from, we do:
lxc init ubuntu:migratee
To list all your containers, you can do:
To get more information from a specific container, you can do:
Finally, we have to add both of our LXDs as non unix-sockets remotes. For this we have to check what IP each VM has in the network running ifconfig on them.
lxc remote add lxd2 otherhost:8443
Now we have our VMs connected and all the configuration set up, we need to install one last dependency:
sudo apt install criu
And we should be able to do
lxc start migratee#if your container is not running yet
lxc move lxd:migratee lxd2:migratee
We cover all these steps in the 2nd and 3rd part of the tutorial series: