How to build and deploy a Kubernetes node image on Debian / KVM with two commands

Cedric Nanni
2 min readMar 5, 2024

--

Kubernetes runs on VMs and bare metal. We are going here to describe a method to build and deploy Kubernetes nodes on top of a KVM/qemu hypervisor host.

The requirements to run the nodes are:

  • One Debian host where the VMs will be deployed. KVM/qemu and libvirt must be installed.
  • Another Debian host to build the images. It could be a VM that runs on top of the hypervisor host or it could be the hypervisor itself.

We need first to prepare the environment by copying the scripts on the Debian host that will be used to build the images. The scripts are downloadable form a GitHub repository.

git clone https://github.com/aprilsoftware/glia-vm.git

Install dependencies.

sudo apt install qemu-utils parted debootstrap packagekit

Create a folder for the images.

mkdir -p ~/img

Then let’s build our first image.

glia-vm/debian/buildvm --path ~/img \
--name server1 \
--release bookworm \
--domain example.com \
--hostname server1 \
--ip 192.168.0.110 \
--gateway 192.168.0.1 \
--nameserver 192.168.0.1 \
--size 50G \
--ask-root-password \
--ask-glia-password \
--modules kubernetes/install_1.29

Once the image has been built, you can deploy it.

glia-vm/debian/deployvm --path ~/img \
--name server1 \
--host glia@hypervisor-host \
--destination /data/vm \
--vcpus 1 \
--memory 2048 \
--network br0 \
--delete-image

Repeat the operation as many time as many hosts you need.

Finally as described in Kubernetes documentation, you can initialize your cluster on the control-plane node.

kubeadm init --pod-network-cidr=10.86.0.0/16

Once initialized, you should get something similar to this.

To start using your cluster, you need to run the following as a regular user:

mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config

Alternatively, if you are the root user, you can run:

export KUBECONFIG=/etc/kubernetes/admin.conf

You should now deploy a pod network to the cluster.
Run "kubectl apply -f [podnetwork].yaml" with one of the options listed at:
https://kubernetes.io/docs/concepts/cluster-administration/addons/

Then you can join any number of worker nodes by running the following on each as root:

kubeadm join 192.168.0.100:6443 --token x36skg.hkyg3vqd8s3hbfoc \
--discovery-token-ca-cert-hash sha256:d63dfb51ff1e98a55ee0f284affe7fd9df8f1b126f06156487e22c246dbf7084

Conclusion

buildvm and deployvm let you build and deploy a VM on KVM/qemu with two commands.

--

--