Running Ubuntu on Kubernetes with KubeVirt v0.3.0

You have this image, of a VM, which you want to run - alongside containers - why? - well, you need it. Some people would say it’s dope, but sometimes you really need it, because it has an app you want to integrate with pods.

Here is how you can do this with KubeVirt.

1 Deploy KubeVirt

Deploy KubeVirt on your cluster - or follow the demo guide to setup a fresh minikube cluster.

2 Download Ubuntu

While KubeVirt comes up (use kubectl get --all-namespaces pods), download Ubuntu Server

3 Install kubectl plugin

Make sure to have the latest or recent kubectl tool installed, and install the pvc plugin:

curl -L https://github.com/fabiand/kubectl-plugin-pvc/raw/master/install.sh | bash

4 Create disk

Upload the Ubuntu server image:

$ kubectl plugin pvc create ubuntu1704 1Gi $PWD/ubuntu-17.04-server-amd64.iso disk.img
Creating PVC
persistentvolumeclaim "ubuntu1704" created
Populating PVC
pod "ubuntu1704" created
total 701444
701444 -rw-rw-r--    1 1000     1000      685.0M Aug 25  2017 disk.img
Cleanup
pod "ubuntu1704" deleted

5 Create and launch VM

Create a VM:

$ kubectl apply -f -
apiVersion: kubevirt.io/v1alpha1
kind: VirtualMachinePreset
metadata:
  name: large
spec:
  selector:
    matchLabels:
      kubevirt.io/size: large
  domain:
    resources:
      requests:
        memory: 1Gi
---
apiVersion: kubevirt.io/v1alpha1
kind: OfflineVirtualMachine
metadata:
  name: ubuntu
spec:
  running: true
  selector:
    matchLabels:
      guest: ubuntu
  template:
    metadata:
      labels: 
        guest: ubuntu
        kubevirt.io/size: large
    spec:
      domain:
        devices:
          disks:
            - name: ubuntu
              volumeName: ubuntu
              disk:
                bus: virtio
      volumes:
        - name: ubuntu
          claimName: ubuntu1710

6 Connect to VM

$ ./virtctl-v0.3.0-linux-amd64 vnc --kubeconfig ~/.kube/config ubuntu

Final notes - This is booting the Ubuntu ISO image. But this flow should work for existing images, which might be much more useful.

::: {#footer} [ March 12th, 2018 4:56pm ]{#timestamp} [kubernetes]{.tag} [kubevirt]{.tag} [ubuntu]{.tag} [virtualization]{.tag} :::