Prepare 3 Ubuntu nodes for Kubernetes cluster on Ubuntu headless server

For this first post, I will be preparing 3 VMs on Virtual Box. These VMs will be the base for my coming experimentations with Kubernetes, Openshift and different tools.

Since this is my first post, a quick explanation of my environment.

I am working off of a an HP ProLiant ML 350p Gen8 that I acquired as a refurbished server. My goal was to use it as a hobby during COVID days. Then, work picked up and I had to put that idea on the side until now. Last week I was playing with it to setup the OS and I got the idea to share my experimentation and, over time, this might be an interesting source of tips and tricks. So I’m going to document my journey of fun with this home lab. Note that everything I do is a home lab and in noway should it be considered production ready installation.

I haven’t documented the process to update the firmware (those fans were really noisy at for no real reason until I found the iLo4 firmware update on reddit). I also didn’t documented the process to install the OS. There’s plenty of people doing it on the web so I will let you search for that :) I may also do it later if I don’t have inspiration.

The OS that I have installed on this server is Ubuntu 24.04 server. I also installed Virtualbox that allows me to create virtual servers for my fun.

Deploying 3 nodes

I want to build a Kubernetes cluster with one master node and two worker nodes. In order to do that, I will setup 3 virtual servers. These 3 nodes will be running on VirtualBox headless since I didn’t want to deploy the UI on my host server. Therefore, I will use command lines to enable everything.

Roughly, I will be reproducing the following architecture:

In order to create the 3 nodes, I use Osboxes images. With that image, we will prepare a base VM that will be our template that will be used to be reproduced 3 times.

So today I will do what is in the “Virtualbox” rectangle. ie:

  1. Prepare my base image (UbuntuBase)
  2. Clone that image 3 times (KubeMaster, KubeWorker1 and KubeWorker2)
  3. Set the Virtualbox private network
  4. Test the environment.

Prepare the Base VM using VirtualBox CLI

I downloaded the image from Osboxes.com. The reason is that I find these VMs to be quite handy and it provides me with one less step to do. I will skip the details to download this to my server but the picture below shows which version I selected.
https://www.osboxes.org/ubuntu-server/


The file downloaded from OsBoxes is named 64bit.7z . Not very convenient but hey! I don’t make the rules! 😊

Let’s extract this one.

Then we’ll move it to a nice and warm directory. Basically, this is where I store my virtualbox images.
mkdir VirtualBoxVMs

mkdir VirtualBoxVMs
mkdir VirtualBoxVMs/Disks
mv ./64bit/ ./VirtualBoxVMs/Disks/
cd ./VirtualBoxVMs/Disks/
mv 64bit/ UbuntuSrv22.04

Create the base vm from the Osboxes image

  1. Add a host only network interface (if it does not exist)
VBoxManage hostonlyif create  

2. Create a new base VM in VirtualBox

VBoxManage createvm --name BaseKubeNode --ostype Ubuntu_64 --register

2. Set up the virtual hardware resources

VBoxManage modifyvm BaseKubeNode --cpus 2 --memory 4096 --nic1 bridged --bridgeadapter1 eno1 --nic2 hostonly --hostonlyadapter2 vboxnet0

Explanation:

  • --cpus 2 – Sets 2 CPU cores.
  • --memory 4096 – Allocates 4GB of RAM.
  • --nic1 bridged – Connects the first NIC to the bridged adapter for external network communication.
  • --bridgeadapter1 eno1 – Links it to the correct physical adapter (eno1).
  • --nic2 hostonly – Creates a private host-only network for internal communication between nodes.
  • --hostonlyadapter2 vboxnet0 – Assigns it to a specific host-only network adapter.

4. Attach the osboxes VM disk

VBoxManage storagectl BaseKubeNode --name "SATA Controller" --add sata --controller IntelAhci

VBoxManage storageattach BaseKubeNode --storagectl "SATA Controller" --port 0 --device 0 --type hdd --medium "/home/kubeadmin/VirtualBoxVMs/Disks/UbuntuSrv22.04/Ubuntu Server 22.04 (64bit).vdi"

5. Create a snapshot of the base VM (optional)

VBoxManage snapshot BaseKubeNode take "CleanInstall"

Clone the base VM for each Kubernetes Node

We will now create the 3 nodes: KubeMaster, KubeWorker1, and KubeWorker2. I like when the IP addresses are allocated by my DHCP server. I registered the 3 nodes on my DHCP with their MAC addresses and the DHCP server should allocate 192.168.0.210 to KubeAdmin, 192.168.0.211 to KubeWorker1 and 192.168.0.212 to KubeWorker2

Since I want this script to be reproducible, I will enforce the allocation of MAC addresses to my new VMs.

  1. Clone the base VM for each node
VBoxManage clonevm BaseKubeNode --name KubeMaster --register --basefolder /home/kubeadmin/VMs 
VBoxManage clonevm BaseKubeNode --name KubeWorker1 --register --basefolder /home/kubeadmin/VMs 
VBoxManage clonevm BaseKubeNode --name KubeWorker2 --register --basefolder /home/kubeadmin/VMs

The VBoxManage clonevm command is used to create copies (clones) of a VirtualBox virtual machine (VM). In this case, it will take the base VM we created (BaseKubeNode) and produce three independent clones: KubeMaster, KubeWorker1, and KubeWorker2. Each of these cloned VMs will have its own configuration and storage but will initially be a replica of the original base VM.

command options explained:

  • BaseKubeNode: This is the name of the source VM we are cloning. BaseKubeNode is the base VM that was previously configured with the desired hardware and software setup.
  • –name KubeMaster: This specifies the name of the new VM that will be created. In this case, KubeMaster will be the name of the master node in our Kubernetes cluster.

    When we run the command for the worker nodes, we will use different names (KubeWorker1 and KubeWorker2) to create separate VMs based on the same base image.
  • --register After cloning, this option automatically registers the new virtual machine in the VirtualBox GUI (if you use the GUI) and internal configuration. Without this flag, the cloned VM would not appear in the VirtualBox Manager until you manually register it.
  • --basefolder /home/kubeadmin/VMs: This option specifies the base folder where the cloned VM’s files (such as disk images, snapshots, and configuration) should be stored.

    In this example, the cloned VM KubeMaster will have its files located in the /home/kubeadmin/VMs directory.

2. Modify the network settings to match the reserved MAC addresses. This can be useful it your router determines the ip address based on MAC address.

Bash
VBoxManage modifyvm KubeMaster --macaddress1 080027996558 
VBoxManage modifyvm KubeWorker1 --macaddress1 0800273B70C3
VBoxManage modifyvm KubeWorker2 --macaddress1 080027D09E53
  1. Configure each VM’s private IP addresses. This will setup static IPs for internal communication. (make sure your MACADDRESS2 are different from each other and from the MACADDRESS1 above)
Bash
VBoxManage modifyvm KubeMaster --nic2 hostonly --hostonlyadapter2 vboxnet0 --macaddress2 080027F69558 
VBoxManage modifyvm KubeWorker1 --nic2 hostonly --hostonlyadapter2 vboxnet0 --macaddress2 080027FF6B70 
VBoxManage modifyvm KubeWorker2 --nic2 hostonly --hostonlyadapter2 vboxnet0 --macaddress2 080027D09E53

Start the VMs and Configure Each Node

  1. Start the VMs
VBoxManage startvm KubeMaster --type headless 
VBoxManage startvm KubeWorker1 --type headless 
VBoxManage startvm KubeWorker2 --type headless

Since we operate on a ubuntu server host without user interface, in other words “headless”, we’ll be running our vm as such too. Hence the –type headless in the commands above.

  1. SSH into each node and configure the static IPs and hostnames to match your network layout. Example for KubeMaster. Since this is the first time that we connect to the VM, we will need to use the Osboxes user/password. By default, Osboxes user and password are:
    user: osboxes
    password: osboxes.org
ssh osboxes@192.168.0.210
  1. Create the kubeadmin user inside each VM. After logging in using the osboxes user, we can manually create a new kubeadmin user and configure the necessary permissions. The commands to execute inside each VM (KubeMaster, KubeWorker1, and KubeWorker2) are:
  • Create the `kubeadmin` user
sudo adduser kubeadmin
  • Add `kubeadmin` to the sudo group
sudo usermod -aG sudo kubeadmin
  • Exit from Osboxes
exit
  1. Repeat steps 2 and 3 on the other 2 nodes (ie: KubeWorker1 and KubeWorker2)

At this stage, we now have 3 VMs that should be available on our network. Note that I have configured my router such that the DHCP will allocate the IP address based on the MAC address of the connected machine. It is also possible to configure the VM itself such that it will have a static IP address. I will leave that for the user. But, as a hint, you will need to modify the /etc/netplan/50-cloud-init.yaml file to suit your needs.

That’s it for now! Next time we’ll start configuring our Kubernetes nodes.

en_USEnglish
Scroll to Top