Skip to content

Latest commit

 

History

History
163 lines (119 loc) · 4.34 KB

LXD.md

File metadata and controls

163 lines (119 loc) · 4.34 KB

How to set up a local MAAS with LXD

Having a locally running MAAS where you can deploy your own virtual machines can be useful for testing things in the UI. This tutorial will take you through the process of setting up MAAS in a LXD container, and registering your host system as a LXD host that can provision virtual machines through MAAS.

Prerequisites

Install and initialise LXD

  1. Disable your firewall so your containers can communicate with your local network
sudo ufw disable
  1. Install LXD
sudo snap install lxd
  1. Initialise LXD
sudo lxd init --auto

You can remove the --auto flag if you want to go through the initialisation steps yourself - the defaults are fine for the purpose of this setup however.

Set up LXD networks and profiles

You'll need a network where MAAS can provide DHCP, this will be where your VMs are provisioned.

  1. Create and edit the maas-kvm network
lxc network create maas-kvm
lxc network edit maas-kvm
  1. Paste the following config, and save
name: maas-kvm
description: ""
type: bridge
managed: true
status: Created
config:
  ipv4.address: 10.20.0.1/24
  ipv4.dhcp: "false"
  ipv4.nat: "true"
  ipv6.address: none
used_by: []
locations:
  - none
  1. Set the HTTPS address for LXD (this enables communication with your local network)
lxc config set core.https_address [::]:8443
  1. Create and edit the maas-container profile
lxc profile create maas-container
lxc profile edit maas-container
  1. Paste the following config, and save
name: maas-container
description: MAAS region container
config: {}
devices:
  eth0:
    network: lxdbr0
    type: nic
  eth1:
    network: maas-kvm
    type: nic
  root:
    path: /
    pool: default
    type: disk

Launch and configure a container for the MAAS region

  1. Launch an Ubuntu container with the maas-container profile
lxc launch ubuntu:jammy some-sensible-name -p default -p maas-container
  1. Enter the shell for the container, and switch to the ubuntu user
lxc shell some-sensible-name
su ubuntu
  1. Inside the container, create a netplan config to give the container an address on the maas-kvm network
sudo nano /etc/netplan/99-maas-kvm-net.yaml
  1. Paste the following config, and save
network:   
  ethernets:  
    eth1:  
      addresses: [10.20.0.2/24]
  version: 2
  1. Apply the new netplan configuration
sudo netplan apply

Install and initialise MAAS

  1. Install the latest MAAS snap, and the test database
sudo snap install maas --channel=latest/edge
sudo snap install maas-test-db --channel=latest/edge
  1. Initialise MAAS with the following command
sudo maas init region+rack --maas-url="http://10.20.0.2:5240/MAAS" --database-uri maas-test-db:///

Take note of the maas-url here, you'll need it to log into the UI later.

  1. Create your admin user
sudo maas createadmin

Configure your host machine as a KVM host in MAAS

  1. Paste the maas-url from step 15 into your browser, and log into MAAS UI. Make sure you import your SSH keys from Launchpad or GitHub
  2. Click on "Subnets" in the navigation, and then click on "10.20.0.0/24". Make sure the gateway IP is "10.20.0.1"
  3. Go to the VLAN for this subnet (it should show up as "untagged"), and reserve a dynamic range from 10.20.0.100 to 10.20.0.200
  4. Click "Configure DHCP", check "MAAS provides DHCP", and make sure the IP range you just reserved shows up in the form, then submit the form.
  5. On your host machine, enter ip a and note down the IP address of lxdbr0.
  6. Click on "LXD" in the navigation, then click "Add LXD host" and fill in the form. You can paste the IP address from the previous step into the "LXD address" field. Select "Generate new certificate and key", and click "Next".
  7. Run the command shown in the side panel on your host machine to add the newly generated certificate to LXD, then click "Check authentication".
  8. Select "Add new project" and give it a name - this is where MAAS will deploy all new VMS created with this host. Then click "Save LXD host" And that's a wrap! You should now be able to compose virtual machines on your host using MAAS.