How to run a LXD container-based MAAS lab using an lunar host
Host preparation
- LXD >= 5.0
Networking
Create a network for the control plane (MAAS, DB and KVM host):
lxc network create net-lab --type=bridge \
dns.domain=net-lab \
ipv4.address=10.0.1.1/24 \
ipv4.dhcp=true \
ipv4.dhcp.ranges=10.0.1.16-10.0.1.31 \
ipv4.nat=true \
ipv6.address=none
Create an un-managed network for the VMs:
lxc network create net-test --type=bridge \
ipv4.address=10.0.2.1/24 \
ipv4.dhcp=false
Allow remote access to the host LXD daemon
lxc config set core.https_address [::]:8443
Create projects for MAAS
lxc project create proj-maas -c features.images=false -c features.profiles=false
lxc project create proj-lab -c features.images=false -c features.profiles=false
Create a profile for MAAS
This will make easier to create MAAS containers later
lxc profile create prof-maas-lab
cat <<EOF | lxc profile edit prof-maas-lab
config:
user.vendor-data: |
#cloud-config
packages:
- jq
runcmd:
- cat /dev/zero | ssh-keygen -q -N ""
ssh_authorized_keys:
- $(cat ${HOME}/.ssh/id_rsa.pub | cut -d' ' -f1-2)
description: MAAS lab env
devices:
eth0:
type: nic
name: eth0
network: net-lab
eth1:
type: nic
name: eth1
network: net-test
EOF
Containers
Create service containers in the project proj-maas
lxc project switch proj-maas
DB
This container is optional, you can use the maas-test-db snap instead (see bellow)
cat <<EOF | lxc launch ubuntu:jammy lab-db
config:
user.user-data: |
#cloud-config
packages:
- postgresql
runcmd:
- cat /dev/zero | sudo -u ubuntu -- ssh-keygen -q -N ""
ssh_authorized_keys:
- $(cat ${HOME}/.ssh/id_rsa.pub | cut -d' ' -f1-2)
description: MAAS database
devices:
eth0:
type: nic
name: eth0
network: net-lab
EOF
# wait for container initialization
lxc exec lab-db -- cloud-init status --wait
lxc list
Login in the container and prepare the DB
$ ssh ubuntu@10.0.1.31
ubuntu@lab-db:~$
Configure the database
# enable remote access
echo "host sameuser all 10.0.1.0/24 scram-sha-256" | sudo tee -a /etc/postgresql/14/main/pg_hba.conf
echo "listen_addresses ='*'" | sudo tee -a /etc/postgresql/14/main/postgresql.conf
sudo systemctl restart postgresql
sudo -u postgres bash
# create MAAS postgresql user and database
createuser maas -P
createdb -O maas maas
Create MAAS container
lxc launch ubuntu:jammy maas-stable -p default -p prof-maas-lab
# wait for container initialization
lxc exec maas-stable -- cloud-init status --wait
lxc list
Login in the container before executing the remaining commands in this section
$ ssh ubuntu@10.0.1.19
ubuntu@maas-stable:~$
Configure the unmanaged network interface:
sudo tee /etc/netplan/99-net-test.yaml <<EOF
network:
version: 2
ethernets:
eth1:
addresses:
- 10.0.2.254/24
EOF
sudo netplan apply
Install MAAS from the SnapStore
sudo snap install maas
If you created the lab-db
container above, you should setup the MAAS controller to use it, replace DBUSER and DBPASSWD appropriately.
sudo maas init region+rack --database-uri=postgres://DBUSER:DBPASSWD@lab-db/maas
if you prefer to use the maas-test-db
snap, you should install it now and setup MAAS to use it
sudo snap install maas-test-db
sudo maas init region+rack --database-uri maas-test-db:///
Create the admin user
sudo maas createadmin
Authenticate the CLI
maas login admin http://10.0.1.19:5240/MAAS $(sudo maas apikey --user=admin)
Enable NAT
sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
Tasks done using the UI
- Enable DHCP on net-test
- Configure MAAS as network gateway
- Add Host as a KVM