Deploying a Virtual Machine in Kubernetes(!)

tjtharrison
10 min readJan 11, 2024

If you have been following my stories recently, I am training for my Kubernetes exams so have provisioned a self-hosted Kubernetes cluster of 4 (previously 3..) Kubernetes nodes running on some small form factor PCs (Setting up Homelab 3.0).

Recently, I had a requirement to run a few servers for a personal project I was working on (setting up an ELK cluster to POC Kibana security plugins — Article to follow soon!) so started looking into options for running some virtualisation tooling alongside Kubernetes to run a virtual machine but quickly came across the project kubevirt.

Kubevirt allows you to provision virtual machines in Kubernetes, with machines configured as code and deployed into your cluster using CRDs (Custom Resource Definitions) with the Kubevirt operator (super cool!).

Only a few years ago when I was working as a sysadmin, we used to run Kubernetes on Virtual machines on our self hosted hypervisors — It’s wild that this is completely reversed now and we’re running virtual machines on Kubernetes!

This article will cover how to get kubevirt deployed onto your Kubernetes cluster and get your first VM deployed.

Photo by Shubham Dhage on Unsplash

Prerequisites:

  • A working Kubernetes cluster
  • Helm client installed locally
  • Other cluster / node requirements from the Kubevirt install page here.

Foreward

I am going to cover two options here, one is an “out of the box” solution using a disk image provided by Kubevirt running Fedora (recommended), the other is a longer process but covers how to deploy an Ubuntu VM (for the brave, YMMV!).

If you wish to keep things simple, I’ll make a note of steps you can skip if you intend to deploy a Fedora VM.

Installing Kubevirt

First things first, lets create a repository for deploying our resources so we can keep these “GitOps” (I covered the benefits of this on another article I wrote recently (Using Helm Dependencies for third party charts).

Reading through the instructions for deploying Kubevirt (https://kubevirt.io/user-guide/operations/installation/) they only provide Kubernetes…

--

--