Fabian Deutsch: How to run a virtual machine on Kubernetes using KubeVirt

The basic steps we take are:

  1. Build and run the demo VM image
  2. Play with KubeVirt

The purpose of this walk through is just to allow you to get a feeling of how
to work with KubeVirt.
Once you are done, feel free to contribute or try out the
developer setup which is based on vagrant.

If you want to be on the safe side, then please run this demo on Fedora 25.

Let’s start by pulling down the KubeVirt Demo repository:

$ git clone https://github.com/kubevirt/demo.git

How this demo works, is by building a disk image, which is then booted
by qemu. The benefits are that your host is kept isolated and will not be
affected by the demo.

So, let’s build the VM disk image for qemu:

$ cd demo
$ make build

The build can now actually take a while, depending on your internet connection.
Once the image was built, we can run it:

$ ./run-demo.sh

Note that you can now run this command again and again, without the need to
rebuild the image each time.

Now CentOS 7 is booting up. You’ll first be greeted by a grub prompt, and end
up in a login prompt.
You’ll need to login as root without a password:

CentOS Linux 7 (Core)
Kernel 3.10.0-514.el7.x86_64 on an x86_64

Login as 'root' to proceed.

kubevirt-demo login: root
Last login: Thu Feb  2 12:18:05 on ttyS0
[root@kubevirt-demo ~]#

Well done, you are logged into the VM with a hopefully running Kubernetes
cluster which also contains KubeVirt.

Let’s start to play with KubeVirt. KubeVirt is implemented as an add-on to
Kubernetes using TPR (ThirdPartyResources) and custom controllers.
The usage of TPR allows us to reuse Kubernetes’ API, thus we can use the
usual kubectl command to control KubeVirt.

Let’s check that the cluster is up and running:

[root@kubevirt-demo ~]# kubectl get pods
NAME                 READY     STATUS    RESTARTS   AGE
haproxy              1/1       Running   33         16d
libvirtd-90ilw       1/1       Running   10         16d
virt-api             1/1       Running   12         16d
virt-controller      1/1       Running   12         16d
virt-handler-24yw6   1/1       Running   49         16d
[root@kubevirt-demo ~]# 

All good – all pods are running.

Let’s check if there is already any VM defined:

[root@kubevirt-demo ~]# kubectl get vms
No resources found.
[root@kubevirt-demo ~]# 

No – That’s okay. Now, let’s create one, luckily there is a pre-defined one in

[root@kubevirt-demo ~]# cat /vm.json 
   "metadata": {
     "name": "testvm"
   "apiVersion": "kubevirt.io/v1alpha1",
   "kind": "VM",
   "spec": {
        "nodeSelector": {"kubernetes.io/hostname":"kubevirt-demo"},
        "domain": {
          "devices": {
            "interfaces": [
                "source": {
                  "network": "default"
                "type": "network"
          "memory": {
            "unit": "KiB",
            "value": 8192
          "os": {
            "type": {
              "os": "hvm"
          "type": "qemu"
[root@kubevirt-demo ~]# kubectl create -f /vm.json 
vm "testvm" created
[root@kubevirt-demo ~]# kubectl get vms
testvm    VM.v1alpha1.kubevirt.io

But how do we know that it’s really running? This can be done by speaking
to libvirt and learn about the created domain:

[root@kubevirt-demo ~]# virsh list
 Id    Name                           State
 2     testvm                         running

Nice – It’s there. What can we do with it?

Currently not much – you can actually access it using spice and you can stop
it again.

To complete the demo we will now be shutting the VM down:

[root@kubevirt-demo ~]# kubectl get vms
testvm    VM.v1alpha1.kubevirt.io
[root@kubevirt-demo ~]# kubectl delete vms testvm
vm "testvm" deleted
[root@kubevirt-demo ~]# kubectl get vms
No resources found.
[root@kubevirt-demo ~]# virsh list
 Id    Name                           State

[root@kubevirt-demo ~]# 

Congratulations – You just created and delete a VM using KubeVirt via the
Kubernetes API.

If you had issues or want to provide feedback then reach out to us using

Now we need to get round to add disks and network to add some psychedelic colors to the demo.

Source From: fedoraplanet.org.
Original article title: Fabian Deutsch: How to run a virtual machine on Kubernetes using KubeVirt.
This full article can be read at: Fabian Deutsch: How to run a virtual machine on Kubernetes using KubeVirt.


Random Article You May Like

Leave a Reply

Your email address will not be published. Required fields are marked *