Technical architectural analysis, practical configuration manifests, and deployment instructions for KubeVirt Virtualization on K8s: Containers.
KubeVirt deployment (k3s testing completed)
Deploy the KubeVirt operator using the latest KubeVirt version.
Operators are a way to package, deploy, and manage Kubernetes applications. A Kubernetes application is an application deployed on Kubernetes and managed using the Kubernetes API and the kubectl tool. You can think of the Operator as the runtime that manages these types of applications in Kubernetes. To learn more about operators, see the Kubernetes documentation
Here we query GitHub’s API to get the latest release. (Clicking on the text will automatically run the command in the console.)
export KUBEVIRT_VERSION=$(curl -s https://api.github.com/repos/kubevirt/kubevirt/releases/latest | jq -r .tag_name)
echo $KUBEVIRT_VERSION
To deploy KubeVirt Operator, run the following command.
kubectl create -f https://github.com/kubevirt/kubevirt/releases/download/${KUBEVIRT_VERSION}/kubevirt-operator.yaml
Now we deploy KubeVirt by creating a custom resource that triggers the โoperatorโ response and performs the deployment.
kubectl create -f https://github.com/kubevirt/kubevirt/releases/download/${KUBEVIRT_VERSION}/kubevirt-cr.yaml
Next, you need to enable KubeVirt to use software emulation for virtualization. This is essential in a teaching environment, but avoid this step in a production environment as it will result in poor performance.
kubectl -n kubevirt patch kubevirt kubevirt --type=merge --patch '{"spec":{"configuration":{"developerConfiguration":{"useEmulation":true}}}}'
Install Virtctl
While waiting for the KubeVirt operator to start all the Pods, you can take your time downloading the clients needed for the next step.
virtctl is a client utility that helps you interact with the VM (start/stop/console, etc.):
wget -O virtctl https://github.com/kubevirt/kubevirt/releases/download/${KUBEVIRT_VERSION}/virtctl-${KUBEVIRT_VERSION}-linux-amd64
chmod +x virtctl
Wait until KubeVirt deployment is complete.
Let’s check the distribution.
kubectl get pods -n kubevirt
When ready, you will see something similar to this:
controlplane $ kubectl get pods -n kubevirt
NAME READY STATUS RESTARTS AGE
virt-api-7fc57db6dd-g4s4w 1/1 Running 0 3m
virt-api-7fc57db6dd-zd95q 1/1 Running 0 3m
virt-controller-6849d45bcc-88zd4 1/1 Running 0 3m
virt-controller-6849d45bcc-cmfzk 1/1 Running 0 3m
virt-handler-fvsqw 1/1 Running 0 3m
virt-operator-5649f67475-gmphg 1/1 Running 0 4m
virt-operator-5649f67475-sw78k 1/1 Running 0 4m
Because multiple deployments are involved, the best way to ensure that the operator is fully installed is to check the operator’s custom resource itself.
kubectl -n kubevirt get kubevirt
When fully deployed, it will look like this:
NAME AGE PHASE
kubevirt 3m Deployed
Now everything is ready and you can run the VM.
VM
Virtual Machine Deployment
The command below applies the YAML definition of the virtual machine to the current Kubernetes environment, defining the VM name, required resources (disk, CPU, memory), etc.ย If you want to learn more about virtual machine definitions, take a look at the vm.yaml file
kubectl apply -f https://kubevirt.io/labs/manifests/vm.yaml
Thanks to the KubeVirt operator, you are creating a virtual machine the same way you create any other Kubernetes resource. Your virtual machine has now been created with Kubernetes resources.
Once the VM resource is created, you can use standard โkubectlโ commands to manage the VM.
kubectl get vms
kubectl get vms -o yaml testvm | grep -E 'runStrategy:.*|$'
The output shows that the VM is not running yet.
To start a VM, use virtctl with the start verb.
./virtctl start testvm
Check the VM status again.
kubectl get vms
VirtualMachine resources contain the definition and state of the VM. A running VM’s instance has an additional resource attachedcalledVirtualMachineInstance.
Once the VM is running, you can check its status.
kubectl get vmis
When ready, run the above command and the following will be output.
NAME AGE PHASE IP NODENAME
testvm 1m Running 10.32.0.11 controlplane
Access the VM (serial console and VNC)
Now that the VM is running, you can access the serial console.
Warning: In some OS and browser environments, you may not be able to exit the serial console during this process.
Note: \^] means press โCTRLโ and โ]โ to exit the console.
./virtctl console testvm
If you have a serial console open in the Killercoda course environment and cannot get out of the console by pressing the \^] key, you can start a new shell by clicking the + button at the top of the terminal window. You can continue with the next steps in the Shutdown and Cleanup section.
In environments with VNC client access, you can use the virtctl vnc command to access the VM’s graphical console.
Closing and Cleaning up
Similar to starting a VM, stopping it can be done using the virtctl command.
./virtctl stop testvm
Finally, you can use kubectl to delete the VM like any other Kubernetes resource.
kubectl delete vms testvm




Leave a Reply