8.1. Guest agent
In many of the available cloud images, the qemu-guest-agent package is already installed. If it’s not preinstalled you can use one of the previously learned concepts to install the package.
Task 8.1.1: Start a virtual machine and explore guest agent information
In this lab we are going to reuse the virtual machine we created in the 4.2. Cloud-init lab.
Start the cloud-init virtual machine using the following command:
virtctl start lab04-cloudinit --namespace lab-<username>
The presence of the guest agent in the virtual machine is indicated by a condition in the VirtualMachineInstance’s status. This condition shows that the guest agent is connected and ready for use.
As soon as the virtual machine has started successfully (kubectl get vm lab04-cloudinit --namespace lab-<username> STATUS Running) we can use the following command to display the VirtualMachineInstance object, either looking at its definition:
kubectl get vmi lab04-cloudinit -o yaml --namespace lab-<username>
Or by describing the resource:
kubectl describe vmi lab04-cloudinit --namespace lab-<username>
Check the status.conditions and verify whether the AgentConnected condition is True:
apiVersion: kubevirt.io/v1
kind: VirtualMachineInstance
[...]
spec:
[...]
status:
conditions:
- lastProbeTime: null
lastTransitionTime: "2024-10-05T12:02:40Z"
status: "True"
type: Ready
- lastProbeTime: null
lastTransitionTime: null
status: "True"
type: LiveMigratable
- lastProbeTime: "2024-10-05T12:02:56Z"
lastTransitionTime: null
status: "True"
type: AgentConnected
[...]
In case the guest agent could connect successfully, there will be additional operating system information shown in the VirtualMachineInstance resource’s status, such as:
status.guestOSInfo- Contains operating system runtime datastatus.interfaces- Shows QEMU interfaces merged with guest agent interfaces data
Explore the additional information.
status:
[...]
guestOSInfo:
id: fedora
[...]
interfaces:
[...]
Task 8.1.2: Guest agent information through virtctl
In addition to the status section in the VirtualMachineInstance resource, it’s also possible to get additional information from the guest agent via virtctl.
Use the following commands to get the information using virtctl:
virtctl guestosinfo lab04-cloudinit --namespace lab-<username>
The guestosinfo sub-command will return the whole guest agent data.
If you’re only interested in the userlist or filesystemlist data, you can execute the following commands:
virtctl userlist lab04-cloudinit --namespace lab-<username>
virtctl fslist lab04-cloudinit --namespace lab-<username>
The full QEMU guest agent protocol reference can be found at https://qemu.weilnetz.de/doc/3.1/qemu-ga-ref.html .
End of lab
The guest agent information is a neat way to find out more about your running virtual machines and to monitor your workload.
Cleanup resources
You have reached the end of this lab. Please stop your running virtual machines to save resources on the cluster.
Stop the VirtualMachineInstance again:
virtctl stop lab04-cloudinit --namespace lab-<username>