Skip to main content
In this lesson we’ll provision VMs for a kube-node2 lab cluster: one Kubernetes control plane (master) and two worker nodes. The environment uses VirtualBox as the hypervisor and Vagrant to automate spinning up VMs with a reproducible configuration. Using Vagrant ensures each user can bring up the same VM layout with a single command. Why follow this approach?
  • Reproducible local Kubernetes labs for practicing kubeadm-based installs.
  • Consistent network and host configuration across machines.
  • Simple automation for VM creation, provisioning, and SSH access.
Prerequisites
A screenshot of the VirtualBox "Download VirtualBox" webpage showing version 7.0.6 platform packages, links, and documentation. The page header and VirtualBox logo are visible along with a left-side navigation menu.
Get the prepared Vagrantfile and provisioning scripts
  1. Clone the course repository (replace <repo-owner> and <repo-name> with the real values for your copy):
  1. Change into the repository and confirm the Vagrantfile is present:
Inspect the Vagrantfile Open the Vagrantfile in a text editor to understand how the VMs are defined. The provided Vagrantfile creates one master and two worker nodes and puts them on a host-only network (192.168.56.0/24). It also mounts the repository into each VM at /vagrant and runs shell provisioners to configure /etc/hosts and DNS. Key excerpts (abridged) from the Vagrantfile:
Notes about the configuration
  • Base box: ubuntu/bionic64.
  • Host-only network: 192.168.56.0/24 (configured via node.vm.network :private_network).
  • SSH forwarding: the Vagrantfile forwards each VM’s port 22 to a host port, allowing vagrant ssh and direct SSH via the forwarded port.
  • Provisioners: the scripts setup-hosts.sh and update-dns.sh are run inside each VM to populate /etc/hosts and update DNS.
Bring up the VMs Vagrant simplifies the lifecycle of these VMs. Typical workflow:
  1. Check VM state:
Example output when machines are not yet created:
  1. Create and provision all VMs:
This will:
  • Download the base box (ubuntu/bionic64) if needed.
  • Create and configure the VirtualBox VMs.
  • Run the configured shell provisioners (e.g., /vagrant/ubuntu/vagrant/setup-hosts.sh).
A successful vagrant up shows logs like:
After provisioning completes, verify all VMs are running:
Example:
Common commands Troubleshooting: Guest Additions
If you see a message about Guest Additions version mismatch (for example, “Guest Additions Version: 5.2.42, VirtualBox Version: 6.1”), it usually does not prevent SSH or provisioning. However, shared folder (synced folder) support can fail in some cases. If you encounter shared-folder problems, install matching Guest Additions inside the VM or update VirtualBox on the host so versions align.
Connect to the VMs Use Vagrant’s SSH convenience command to open an interactive shell on any node:
A sample session inside a worker node:
After logout you return to your host shell. Repeat vagrant ssh <name> to access other nodes.
A screenshot of a GitHub repository page for a "Certified Kubernetes Administrator (CKA) Course." It shows the file list (folders like docs, images, resources), the README header with course sections, and repo metadata such as stars, forks, and contributors.
Summary checklist
  • Install VirtualBox and Vagrant on the host machine.
  • Clone the course repository to obtain the Vagrantfile and provisioning scripts.
  • Inspect the Vagrantfile to learn about VM roles, memory/CPU, network, and forwarded ports.
  • Run vagrant up to create and provision kubemaster, kubenode01, and kubenode02.
  • Use vagrant ssh <name> to connect to each node and validate the environment.
Next steps After the VMs are provisioned and reachable, proceed to:
  • Initialize the Kubernetes control plane on the master node with kubeadm init.
  • Configure kubectl on the master and copy the join command to add worker nodes.
  • Run kubeadm join on each worker to complete the cluster setup.
Links and references

Watch Video