KVM, virtual bridge and APIs

Been exploring KVM on Debian12 recently on my lab machines and I wanted to run a few API tests also, and so to get it to work I had to have my VMs on the same subnet as my physical machines first which is a setup I never did before.

I checked my hosts with lscpu | grep -i virtualization and none had the VT-x set on which is the virtualisation setting for Intel CPUs, so I embarked on a journey on UEFI get the feature up and after a bit of fiddling eventually turned it on.

Then I installed a full suite of tools to play with KVM sudo apt install -y qemu-kvm libvirt-daemon-system libvirt-clients bridge-utils virtinst virt-manager and launched my first two KVM domains with Oracle Linux 8 on them. It worked like a charm and I additionally tried a few options with virsh, the command line interface for VMs, instead of the GUI from virt-manager.

After that wanted to access my VM command line from the physical host terminal to see if I could do some bootstrapping this way, I could have used SSH but wanted to try something different, so used the serial line instead which required a bit of setup on the guest machine. Setup I actually can’t find online anymore. (I will edit the post and add it.)

Once done with prior steps I got these machines on my LAN instead of them being simply NAT’ed, I needed them to be reachable and visible to each other on the same network. I did a bit of research and ended on this brilliant video here, which saved me a lot of time and I simply followed the recommended steps. The objective here is to create a virtual bridge on your host and then re-attach your physical NIC to this virtual bridge, as well as any VMs running on your host; I was unfamiliar with the concept, but this make entire sense.

Finally, I was now ready to launch a little python script that would do a calculus when sent two parameter and return the result, I bound it to port 8092 and lifted the firewall rules on the corresponding port. I was now ready to call my API from any machine in the local network with curl and it worked very nicely.

Leave a Reply

Your email address will not be published. Required fields are marked *