Labs - Use KubeVirt

Use KubeVirt

  • You can experiment with this lab online at Killercoda

Create a Virtual Machine

Download the VM manifest and explore it. Note it uses a container disk and as such doesn’t persist data. Such container disks currently exist for alpine, cirros and fedora.

wget https://kubevirt.io/labs/manifests/vm.yaml
less vm.yaml

Apply the manifest to Kubernetes.

kubectl apply -f https://kubevirt.io/labs/manifests/vm.yaml
virtualmachine.kubevirt.io "testvm" created
  virtualmachineinstancepreset.kubevirt.io "small" created

Manage Virtual Machines (optional):

To get a list of existing Virtual Machines. Note the running status.

kubectl get vms
kubectl get vms -o yaml testvm

To start a Virtual Machine you can use:

virtctl start testvm

If you installed virtctl via krew, you can use kubectl virt:

# Start the virtual machine:
kubectl virt start testvm

# Stop the virtual machine:
kubectl virt stop testvm

Alternatively you could use kubectl patch:

# Start the virtual machine:
kubectl patch virtualmachine testvm --type merge -p \
    '{"spec":{"running":true}}'

# Stop the virtual machine:
kubectl patch virtualmachine testvm --type merge -p \
    '{"spec":{"running":false}}'

Now that the Virtual Machine has been started, check the status. Note the running status.

kubectl get vmis
kubectl get vmis -o yaml testvm

Accessing VMs (serial console)

Connect to the serial console of the Cirros VM. Hit return / enter a few times and login with the displayed username and password.

virtctl console testvm

Disconnect from the virtual machine console by typing: ctrl+].

Controlling the State of the VM

To shut it down:

virtctl stop testvm

To delete a Virtual Machine:

kubectl delete vm testvm

This concludes this section of the lab.

You can watch how the laboratory is done in the following video:

Next Lab