Kubevirt

Upstream docs: https://kubevirt.io/quickstart_minikube/

Installation

Minikube easy way

minikube addons enable kubevirt

Manual

Deploy kubevirt operator:

export VERSION=$(curl -s https://api.github.com/repos/kubevirt/kubevirt/releases | grep tag_name | grep -v -- '-rc' | sort -r | head -1 | awk -F': ' '{print $2}' | sed 's/,//' | xargs)
kubectl create -f https://github.com/kubevirt/kubevirt/releases/download/${VERSION}/kubevirt-operator.yaml

Validation

Check the installation by running:

kubectl get po -w -n kubevirt

kubectl get kubevirt.kubevirt.io/kubevirt -n kubevirt -o=jsonpath="{.status.phase}"

kubectl logs pod/kubevirt-install-manager -n kube-system

All pods should be running and a status of "Deployed" should shown.

Virtctl

VirtCTL is a CLI that can be used to manage KVM resources within the kuberntes cluster:

VERSION=$(kubectl get kubevirt.kubevirt.io/kubevirt -n kubevirt -o=jsonpath="{.status.observedKubeVirtVersion}")
ARCH=$(uname -s | tr A-Z a-z)-$(uname -m | sed 's/x86_64/amd64/') || windows-amd64.exe
echo ${ARCH}
curl -L -o virtctl https://github.com/kubevirt/kubevirt/releases/download/${VERSION}/virtctl-${VERSION}-${ARCH}
chmod +x virtctl
sudo install virtctl /usr/local/bin

Using

Create a vm.yaml file and add the following content:

apiVersion: kubevirt.io/v1
kind: VirtualMachine
metadata:
  name: testvm
spec:
  running: false
  template:
    metadata:
      labels:
        kubevirt.io/size: small
        kubevirt.io/domain: testvm
    spec:
      domain:
        devices:
          disks:
            - name: containerdisk
              disk:
                bus: virtio
            - name: cloudinitdisk
              disk:
                bus: virtio
          interfaces:
          - name: default
            bridge: {}
        resources:
          requests:
            memory: 64M
      networks:
      - name: default
        pod: {}
      volumes:
        - name: containerdisk
          containerDisk:
            image: quay.io/kubevirt/cirros-container-disk-demo
        - name: cloudinitdisk
          cloudInitNoCloud:
            userDataBase64: SGkuXG4=

Appply the file by running kubectl apply -f vm.yaml.

Check if the VM resource was created:

kubectl get vms

NAME     AGE   STATUS    VOLUME
testvm   22s   Stopped 

The VM can be started by patching the VM resource:

kubectl patch virtualmachine testvm --type merge -p '{"spec":{"running":true}}'

Setting spec.running to false will stop the VM.

Check the VM status again:

kubectl get vms
NAME     AGE     STATUS    VOLUME
testvm   2m44s   Running

A pod was created for our testvm:

kubectl get po
NAME                         READY   STATUS    RESTARTS   AGE
virt-launcher-testvm-4jhxl   2/2     Running   0          3m59s

License

MIT