# Building a kubeadm Cluster (Part 1): Preparing Practice VMs with KVM and cloud-init

> A comparison of common Kubernetes setup tools, then using virt-install with an Ubuntu Cloud Image and cloud-init to quickly create three VMs for kubeadm

- URL: https://lcxlab.com/en/post/cka-kubeadm-lab-setup
- Author: Miles Hsu
- Published: 2026-10-22
- Updated: 2026-10-28
- Category: DevOps
- Series: Certified Kubernetes Administrator (CKA) #3
- Tags: CKA, kubeadm, Kubernetes, ubuntu, QEMU
- License: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/deed.en)

---

## kubeadm 

The main setup tool you will run into during the CKA exam is `kubeadm`. It is positioned more like the officially recommended way to build a practice cluster: conceptually, it is a pile of loose building blocks that you have to assemble yourself. That makes it a great fit for a hands-on certification exam. It is also the hardest of the bunch, but it is something every operator who wants to truly understand Kubernetes needs to learn.

## Comparing Common Kubernetes Setup Tools

| Tool | Key Characteristics | Best For |
|--|--|--|
| `kubeadm` | The official K8s initialization tool built on best practices. Fully follows the community-standard architecture; you configure the CRI and CNI yourself. | Learning K8s internals in depth, preparing for CKA/CKS, building standard self-managed clusters. |
| `minikube` | The classic single-node tool. Simulates a full node with a VM (VirtualBox/Docker/QEMU). | Beginners getting familiar with native K8s components, simple tests on a single machine. |
| `kind (Kubernetes in Docker)` | Runs an entire K8s cluster inside Docker containers. Starts very fast and supports multi-node clusters. | CI/CD testing, simulating multi-node clusters, lightweight development. |
| `k3s` | An ultra-lightweight distribution from Rancher. Removes outdated or unneeded components (such as in-tree cloud providers) and uses SQLite instead of etcd by default. | Edge computing, IoT, resource-constrained machines, or lightweight production environments. |
| `RKE2` | Rancher's enterprise-grade, security-focused distribution. Every component runs as a Pod (secure by default) and is hardened to the CIS benchmark by default. | On-premise enterprise production environments and scenarios with strict security requirements. |

---

## Building a kubeadm Cluster from Scratch

If you have bought Mumshad Mannambeth's "Certified Kubernetes Administrator (CKA) with Practice Tests" course on Udemy, it comes with KodeKloud labs to practice with. KodeKloud also offers various Playgrounds where you can practice directly on sandbox VMs.

![180421](https://lcxlab.com/images/posts/cka-kubeadm-lab-setup/180421.webp)
>Screenshot from KodeKloud

To understand Kubernetes' core components, what each one is responsible for, and how they interact through hands-on practice, and to gradually learn how to manage a Kubernetes cluster close to a production environment, I will use Ubuntu as the operating system, create virtual machines with virt-install, and deploy a Kubernetes cluster with kubeadm.

Users on different operating systems can pick a lab environment that suits their own hardware and needs:

- Windows users: use WSL with a suitable virtualization setup, or create Linux VMs with tools such as Hyper-V or VirtualBox.
- Linux users: create VMs with KVM plus virt-install, virt-manager, GNOME Boxes, or Vagrant.
- MacBook users: on Apple Silicon (M-series) models, consider UTM, Tart, or Parallels Desktop to create Ubuntu ARM64 VMs; on Intel Macs, consider VMware Fusion, VirtualBox, or UTM. Since CPU architecture and virtualization support differ between Mac models, make sure the Ubuntu image, container runtime, and Kubernetes components are compatible with your architecture.

This series starts with building a Kubernetes cluster, then gradually explores how the Control Plane, Worker Nodes, and related components work. Through hands-on deployment, day-to-day operations, troubleshooting, and cluster upgrades, it builds the knowledge and practical experience needed to manage a Kubernetes cluster.

Whether you are on Windows, Linux, or a MacBook, you can put together a lab environment for learning Kubernetes that fits your hardware and use case.

---

### Installing the Tools

Installing virt-install alone is not enough. It is just a CLI for issuing "create a VM" commands; behind it you still need QEMU/KVM and libvirt to actually run the VMs.

If, like me, you are on a Red Hat-based distribution such as Fedora or Rocky Linux, you can install the virtualization package group directly and then start the libvirt services:

```bash
sudo dnf install @virtualization
sudo systemctl enable --now virtqemud.socket virtnetworkd.socket virtstoraged.socket
```

If you are on an Arch Linux-based distribution such as CachyOS or Manjaro, install with pacman:

```bash
sudo pacman -S qemu-base libvirt virt-install dnsmasq
sudo systemctl enable --now libvirtd
```

If you are on a Debian-based distribution such as Ubuntu or Debian, install with apt (the services start automatically after installation):

```bash
sudo apt update
sudo apt install qemu-system-x86 libvirt-daemon-system virtinst
```

For other distributions, look up the installation method for your package manager. For example, Gentoo users can install the corresponding packages through Portage without necessarily compiling anything themselves.

Once installed, make sure libvirt's built-in `default` network is running and set to start automatically on boot. All the VMs below will be attached to this NAT network:

```bash
sudo virsh net-start default
sudo virsh net-autostart default
```
>Verify: run sudo virsh net-list --all and confirm that default shows State active and Autostart yes.

### Quickly Creating Ubuntu VMs

At first I downloaded the Ubuntu Server ISO, booted it with `virt-install --location`, and went through the text-mode installer, but I kept getting stuck on this path:

- The Ubuntu 24.04 live-server ISO keeps its kernel in the `casper/` directory. virt-install does not recognize this layout and fails right away with `Couldn't find kernel for install tree.`
- Even if you point it at the kernel with `kernel=casper/vmlinuz,initrd=casper/initrd` to get it to boot, you still have to complete the entire Subiquity installation over the serial console, and since a kubeadm cluster needs at least three VMs, you would have to do it three times.

So instead I use Ubuntu's official **Cloud Image**: a disk image with the system already installed, combined with cloud-init to set the hostname, account password, and SSH key on first boot. There is no installer to go through, and each VM is up in about ten-odd seconds.

The plan is to create three VMs:

| Hostname | Role | vCPU | Memory | Disk |
|--|--|--|--|--|
| k8s-cp1 | Control Plane | 2 | 4 GiB | 20 GiB |
| k8s-w1 | Worker Node | 2 | 2 GiB | 20 GiB |
| k8s-w2 | Worker Node | 2 | 2 GiB | 20 GiB |

> kubeadm requires at least 2 vCPUs and 2 GiB of memory per node. Anything less will fail the preflight checks in `kubeadm init`.

#### 1. Download the Cloud Image

Put the image in libvirt's default storage directory `/var/lib/libvirt/images/` so that QEMU has permission to read it (putting it under your home directory often runs into permission problems):

```bash
sudo curl -L -o /var/lib/libvirt/images/noble-base.img \
  https://cloud-images.ubuntu.com/noble/current/noble-server-cloudimg-amd64.img
```
>Verify: run sudo qemu-img info /var/lib/libvirt/images/noble-base.img and confirm that the file format is qcow2.

This `noble-base.img` serves only as a read-only "base image". Each VM gets its own disk that uses it as a backing file and records only what differs from the base. All three VMs share the same base image, which saves space and is fast.

#### 2. Prepare an SSH Key

If you don't have an SSH key yet, generate one first. It will be placed into each VM through cloud-init:

```bash
ssh-keygen -t ed25519
```

#### 3. Create the VMs

The loop below does three things for each VM: creates the disk, generates the cloud-init config file, and runs virt-install.

```bash
IMG_DIR="/var/lib/libvirt/images"
SSH_KEY="$(cat ~/.ssh/id_ed25519.pub)"

for node in k8s-cp1:4096 k8s-w1:2048 k8s-w2:2048; do
  NAME="${node%%:*}"
  MEM="${node##*:}"

  # Create a 20G disk backed by noble-base.img
  sudo qemu-img create -f qcow2 -F qcow2 \
    -b "$IMG_DIR/noble-base.img" "$IMG_DIR/$NAME.qcow2" 20G

  # cloud-init: set the hostname, plus the password and SSH key for the default user ubuntu
  cat > "$NAME-user-data.yaml" <<YAML
#cloud-config
hostname: $NAME
password: ubuntu
chpasswd: { expire: false }
ssh_authorized_keys:
  - $SSH_KEY
YAML

  sudo virt-install \
    --name "$NAME" \
    --memory "$MEM" \
    --vcpus 2 \
    --disk "$IMG_DIR/$NAME.qcow2" \
    --os-variant ubuntu24.04 \
    --import \
    --cloud-init user-data="$NAME-user-data.yaml" \
    --network network=default \
    --graphics none \
    --noautoconsole
done
```
>Verify: run sudo virsh list --all and confirm that all three VMs show State running.

What the options do:

- `--import`: the disk already contains an installed system, so boot it directly without an installation step.
- `--cloud-init user-data=...`: virt-install packs the config file into a virtual CD-ROM for cloud-init, attached only on the first boot.
- `--network network=default`: attach to the `default` NAT network started earlier.
- `--noautoconsole`: don't drop into the console automatically after creation, so the loop can move on to the next VM.

#### 4. Connecting and Managing Afterwards

Look up the IP each VM got from the `default` network:

```bash
for n in k8s-cp1 k8s-w1 k8s-w2; do sudo virsh domifaddr "$n"; done
```

Once you have the IP, you can SSH in. The default user on the Cloud Image is `ubuntu`:

```bash
ssh ubuntu@<VM IP>
```
>Verify: after logging in, run hostname and confirm it shows the name set by cloud-init (for example, k8s-cp1).

If the network isn't up yet and you need to get into the VM over the serial port, you can also use the console (username `ubuntu`, password `ubuntu`; press `Ctrl + ]` to exit):

```bash
sudo virsh console k8s-cp1
```

If you break something and want to start over, delete the VM together with its disk and run the loop above again:

```bash
sudo virsh destroy k8s-cp1
sudo virsh undefine k8s-cp1 --remove-all-storage
```

#### 5. Shutting Down, Pausing, and Starting

Day-to-day VM management is also done with `virsh`. The examples below use `k8s-cp1`:

| Action | Command | Description |
|--|--|--|
| Graceful shutdown | `sudo virsh shutdown k8s-cp1` | Sends an ACPI shutdown signal, the same as running `poweroff` inside the VM |
| Force off | `sudo virsh destroy k8s-cp1` | The same as pulling the power plug; use only when the VM is stuck (it does not delete the VM) |
| Pause | `sudo virsh suspend k8s-cp1` | Freezes the CPU and keeps the state in memory; the host's RAM is not released |
| Resume | `sudo virsh resume k8s-cp1` | Continues from where it was paused |
| Save and stop | `sudo virsh managedsave k8s-cp1` | Writes the memory contents to disk, then stops the VM and releases its RAM; the next `start` returns to the saved state |
| Start | `sudo virsh start k8s-cp1` | |
| Autostart on boot | `sudo virsh autostart k8s-cp1` | Starts this VM automatically when the host boots; add `--disable` to turn it off |

Shut down or start all three at once:

```bash
for n in k8s-cp1 k8s-w1 k8s-w2; do sudo virsh shutdown "$n"; done
for n in k8s-cp1 k8s-w1 k8s-w2; do sudo virsh start "$n"; done
```
>Verify: run sudo virsh list --all and confirm that all three VMs show State shut off or running.

> Once the cluster is installed, prefer a graceful `shutdown`. If a VM stays suspended for a long time and is then resumed, its clock falls behind, which can cause problems with certificate validation or etcd, so `suspend` is better suited to short breaks. To stop a VM while keeping its current state, use `managedsave` instead.

---

References:

[1] Ubuntu Cloud Images - https://cloud-images.ubuntu.com/

[2] cloud-init Documentation - https://cloudinit.readthedocs.io/

[3] virt-install - https://github.com/virt-manager/virt-manager/blob/main/man/virt-install.rst

[4] libvirt - https://libvirt.org/

[5] Getting started with virtualization (Fedora Docs) - https://docs.fedoraproject.org/en-US/quick-docs/virtualization-getting-started/
