Setting up a “Virtual MAAS” Test Environment
It can be useful to setup MAAS with KVM for testing and evaluation. This guide will walk you through the process of doing this.
Prerequisites
$ sudo apt install libvirt-bin qemu-kvm cpu-checker
$ sudo snap install lxd
Verify KVM hardware acceleration is available on your local machine.
$ kvm-ok
INFO: /dev/kvm exists
KVM acceleration can be used
Create a LXC Container with KVM
Create a LXC profile that we can reuse in the future if needed. This profile
enables KVM hardware acceleration in the container and installs libvirt in the container.
$ lxc profile create kvm
$ cat <<EOF | lxc profile edit kvm
config:
user.user-data: |
#cloud-config
package_upgrade: true
packages: [libvirt-bin, qemu-kvm, cpu-checker, libvirt-clients, jq]
runcmd:
- cat /dev/zero | ssh-keygen -q -N ""
- cat /root/.ssh/id_rsa.pub >> /root/.ssh/authorized_keys
description: Provide access to /dev/kvm in the container, for hardware accelleration
devices:
kvm:
gid: "1001"
major: "10"
minor: "232"
path: /dev/kvm
type: unix-char
name: kvm
used_by: []
EOF
Now we have created the profile we can launch an instance with it and wait for
the cloud-config to complete.
$ lxc launch ubuntu:bionic bionic-maas-kvm -p default -p kvm
$ lxc exec bionic-maas-kvm -- cloud-init status --wait
Connect to the container
The following steps should all be completed within the container. Start up a
bash shell.
$ lxc shell bionic-maas-kvm
Setup a virsh maas network
We need to setup a network for MAAS to manage within the container, we will do this with virsh.
$ cat << EOF > maas.xml
<network>
<name>maas</name>
<forward mode="nat"/>
<bridge name="maas" stp="off" delay="0"/>
<ip address="172.16.99.1" netmask="255.255.255.0"/>
</network>
EOF
$ virsh net-define maas.xml;
$ virsh net-start maas;
$ virsh net-autostart maas;
$ rm maas.xml
Install MAAS snap
Next we need to install the MAAS snap and use the init command to create a database and then create a admin user.
$ snap install --channel=2.7 maas
$ maas init
Copy the SSH keys
MAAS connects to the KVM host via ssh. We need to copy the SSH keys so MAAS can
access them.
$ cp -r /root/.ssh/ /var/snap/maas/current/root/.ssh
Open the UI
To login the UI, open http://$CONTAINER_IP:5240/MAAS/r/
You can skip the ssh key importing.
Enable DHCP
On the subnets tab click untagged next to the subnet defined in maas.xml,
172.16.99.0/24
and enable DHCP.
Add the KVM host
On the KVM tab click ‘Add KVM’ and use the address qemu+ssh://root@127.0.0.1/system
You should now have a KVM added and you can create virtual machines and use
them within MAAS.