MAAS with KVM: Difference between revisions

From UNamur InfoSec
Jump to navigation Jump to search
No edit summary
 
(4 intermediate revisions by the same user not shown)
Line 9: Line 9:
Start virt-manager -> select QEMU/KVM -> select "edit" -> "connection detail" -> click plus sign to add new connection -> uncheck enable "dhcp4"
Start virt-manager -> select QEMU/KVM -> select "edit" -> "connection detail" -> click plus sign to add new connection -> uncheck enable "dhcp4"


# Allow MAAS to SSH to KVM host
* Allow MAAS to SSH to KVM host
## Enable SSH on hosts:
** Enable SSH on hosts: <p><pre>sudo apt install openssh-server</pre></p>
sudo apt install openssh-server
** Create private and public key for MAAS <p>MAAS will use the private key named "id_rsa" in the /var/snap/maas/current/root/.ssh directory. To generate it:</p>
## 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:
<pre>
<pre>
sudo mkdir -p /var/snap/maas/current/root/.ssh
  sudo mkdir -p /var/snap/maas/current/root/.ssh
cd /var/snap/maas/current/root/.ssh
  cd /var/snap/maas/current/root/.ssh
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
 
== Screenshot ==
[[File:Add-new-virtual-network-via-virt-manager.png|add new virtual network via virt-manager]]
[[File:Kvm-hosts-in-maas-cloud.png|kvm-hosts-in-maas-cloud]]


== References ==
== References ==
https://maas.io/docs/snap/3.1/ui/how-to-manage-vm-hosts
https://maas.io/docs/snap/3.0/ui/how-to-manage-vm-hosts
 
https://linuxize.com/post/how-to-enable-ssh-on-ubuntu-18-04/

Latest revision as of 14:47, 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"

  • Allow MAAS to SSH to KVM host
    • Enable SSH on hosts:

      sudo apt install openssh-server

    • 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
  • 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. 
  • 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
  • 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
  • To add new VMs
  Click KVM -> select KVM host from list -> Take Action -> Compose -> Fill VM specs -> click Compose

Screenshot

add new virtual network via virt-manager kvm-hosts-in-maas-cloud

References

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

https://linuxize.com/post/how-to-enable-ssh-on-ubuntu-18-04/