Run Virtual Machines on Kubernetes - Rafay Product Documentation

Part 3: Deploy VM

What Will You Do

In this part of the self-paced exercise, you will deploy a virtual machine workload to your cluster running KubeVirt.


Step 1: Create Workload Namespace

In this step, you will create a namespace for the virtual machine. The "namespace.yaml" file in the "/getstarted/kubevirt/workload" directory of the forked repository contains the declarative specification for the namespace resource.

rctl create namespace -f namespace.yaml

If you did not encounter any errors, you can optionally verify if everything was created correctly on the controller.

Next, you will publish the namespace to the cluster.

rctl publish namespace vm

Step 2: Deploy Virtual Machine Workload

In this step, you will create a workload resource for the virtual machine. The "vm-workload.yaml" file in the "/getstarted/kubevirt/workload" directory of the forked repository contains the declarative specification for the workload.

The following items may need to be updated/customized if you used alternate names.

name: vm
namespace: vm
project: defaultproject
type: NativeYaml
clusters: kubevirt-cluster
payload: ./vm.yaml

Note that the workload's name is "vm" and it is of type "k8s YAML". The actual k8s YAML file for the VM is in the payload "vm.yaml" file.

rctl create workload vm-workload.yaml

If there were no errors, you should see a message like below

Workload created successfully

Now, let us publish the newly created VM workload to the cluster. The workload can be deployed to multiple clusters as per the configured "placement policy". In this case, you are deploying to a single cluster with the name "kubevirt-cluster".

rctl publish workload vm

Step 3: Verify Workload

In the web console, click on Applications -> Workloads. You should see something like the following.

Now, let us verify the virtual machine is running.

kubectl get vm -n vm

You should see something like the following showing the VM in a running state.

NAME     AGE   STATUS    READY
testvm   50s   Running   True

Step 4: Download KubeVirt's virtctl CLI

The virtctl CLI is needed for the use of advanced features to interact with virtual machines.

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

Step 5: Access Virtual Machine

In this step, you will access the virtual machine using the previously installed virtctl CLI.

virtctl console testvm -n vm

You are now able to use the VM terminal.


Recap

Congratulations! At this point, you have successfully deployed a virtual machine to the Kubernetes cluster and accessed the VM's terminal.