Preparing Virtual Box VM’s to run Kubernetes

Fabio Fernandes
5 min readNov 10, 2020

This week I had to prepare a multinode k8s solution to run on developers’ computers.

Among all the requirements, the solution should be light enough not to compromise the overall machine performance and easy to fine-tune k8s configurations to test with different development approaches.

I worked with Virtual Box VM’s to create my cluster, but I decided to write this guide explaining the process since the network configuration was not so trivial.

The first thing to consider when using virtual boxes to create a Kubernetes cluster is the network.

Virtual box has 3 types of configurable network:

  • NAT — the networking type of the default network adapter when you create a new VM. This gives internet access, but applications running on the host can’t make network connections to the VM.
  • Bridged — with this type, VirtualBox uses a special driver for the host’s physical network interface to create a virtual network interface for the VM. The VM gets an IP on the same network that the host is physically connected to. Host-to-guest communication and internet access are available.
  • Host-only — with this type, VirtualBox creates a virtual network that the host and the VMs are connected to. This allows host-to-guest communication, but this virtual network has no access to the internet.

The goal here is to connect each box from the Host machine via ssh. I will allow us to use scripts to do the provisioning and configurations automatically in the future.

We could achieve it with the bridge network, but then, every time you connect into a different network (connect your computer in different wifi, for example), the VM IP will change, and all the scripts with fixed values will not work anymore.

Other problems would be the communication between the boxes, like NFS configuration, that rely on the IP addresses and would stop working when the IP changes.

The solution I found was the use of a combination of strategies.

  • First, I added a network manager in VirtualBox with a range of IP’s.
  • Then I added one adapter in each of the boxes with the Host-only network type using the previously created network manager.
  • Added another network adapter using NAT type to give access to the internet for our boxes.