Difference between revisions of "MAAS with KVM"

From UNamur InfoSec
Jump to navigation Jump to search
(Created page with "== Introduction == In addition to provision bare metal machines. MAAS supports adding KVM and LXD servers to the MAAS clous, which allow MAAS to compose VMs in KVM server and...")
 
Line 12: Line 12:
## Enable SSH on hosts:
## Enable SSH on hosts:
sudo apt install openssh-server
sudo apt install openssh-server
## Create private and public key for MAAS
## Create private and public key for MAAS
MAAS will use the private key named "id_rsa" in the /var/snap/maas/current/root/.ssh directory. To generate it:
MAAS will use the private key named "id_rsa" in the /var/snap/maas/current/root/.ssh directory. To generate it:
Line 20: Line 19:
sudo ssh-keygen -f id_rsa
sudo ssh-keygen -f id_rsa
</pre>
</pre>
## Add MAAS public key to authorized_keys file
## Add MAAS public key to authorized_keys file
ssh-copy-id -i id_rsa.pub $USER@$VM_HOST_IP
ssh-copy-id -i id_rsa.pub $USER@$VM_HOST_IP
Note: the keys generated by previous command need root permission to access them.  
Note: the keys generated by previous command need root permission to access them.  
## Test qemu+ssh command
## Test qemu+ssh command
If we have virsh client installed, we can use the command check if it is working.  
If we have virsh client installed, we can use the command check if it is working.  
virsh -c qemu+ssh://$USER@$VM_HOST_IP/system list --all
virsh -c qemu+ssh://$USER@$VM_HOST_IP/system list --all
## Add KVM to MAAS
## Add KVM to MAAS
Go to MAAS dashboard -> KVM -> Add KVM -> select "virsh" -> enter "qemu+ssh://$USER@$VM_HOST_IP/system" with correct user and IP in the address field -> click save
Go to MAAS dashboard -> KVM -> Add KVM -> select "virsh" -> enter "qemu+ssh://$USER@$VM_HOST_IP/system" with correct user and IP in the address field -> click save
## To add new VMs
## To add new VMs
Click KVM -> select KVM host from list -> Take Action -> Compose -> Fill VM specs -> click Compose
Click KVM -> select KVM host from list -> Take Action -> Compose -> Fill VM specs -> click Compose
== References ==
== References ==
https://maas.io/docs/snap/3.1/ui/how-to-manage-vm-hosts
https://maas.io/docs/snap/3.1/ui/how-to-manage-vm-hosts

Revision as of 14:32, 6 December 2021

Introduction

In addition to provision bare metal machines. MAAS supports adding KVM and LXD servers to the MAAS clous, which allow MAAS to compose VMs in KVM server and manages like any other machines.

Adding existing KVM to MAAS

  1. Creating virtual network in KVM

MAAS need to provide DHCP for VMs to PXE boot. So we can either disable DHCP in existing network, or create new network with DHCP disabled.

To create new virtual network with virt-manager: Start virt-manager -> select QEMU/KVM -> select "edit" -> "connection detail" -> click plus sign to add new connection -> uncheck enable "dhcp4"

  1. Allow MAAS to SSH to KVM host
    1. Enable SSH on hosts:

sudo apt install openssh-server

    1. Create private and public key for MAAS

MAAS will use the private key named "id_rsa" in the /var/snap/maas/current/root/.ssh directory. To generate it:

sudo mkdir -p /var/snap/maas/current/root/.ssh
cd /var/snap/maas/current/root/.ssh
sudo ssh-keygen -f id_rsa
    1. Add MAAS public key to authorized_keys file

ssh-copy-id -i id_rsa.pub $USER@$VM_HOST_IP Note: the keys generated by previous command need root permission to access them.

    1. Test qemu+ssh command

If we have virsh client installed, we can use the command check if it is working. virsh -c qemu+ssh://$USER@$VM_HOST_IP/system list --all

    1. Add KVM to MAAS

Go to MAAS dashboard -> KVM -> Add KVM -> select "virsh" -> enter "qemu+ssh://$USER@$VM_HOST_IP/system" with correct user and IP in the address field -> click save

    1. To add new VMs

Click KVM -> select KVM host from list -> Take Action -> Compose -> Fill VM specs -> click Compose

References

https://maas.io/docs/snap/3.1/ui/how-to-manage-vm-hosts