Using the virtctl Command-Line Tool

virtctl is the standard KubeVirt command-line client. It complements kubectl with commands that need a streaming connection or a subresource call — opening consoles, uploading and exporting images, hot-plugging disks, and triggering migrations. It ships with KubeVirt; download the binary that matches the cluster's KubeVirt version from the KubeVirt releases and place it on your PATH.

# Example: download virtctl for the cluster's KubeVirt version
VERSION=$(kubectl get kubevirt kubevirt -n kubevirt -o jsonpath='{.status.observedKubeVirtVersion}')
curl -L -o virtctl "https://github.com/kubevirt/kubevirt/releases/download/${VERSION}/virtctl-${VERSION}-linux-amd64"
chmod +x virtctl && sudo mv virtctl /usr/local/bin/

Consoles and access

virtctl console web-01 -n demo        # serial (text) console — see Serial Console
virtctl vnc web-01 -n demo            # graphical VNC console — see VNC
virtctl ssh user@web-01 -n demo       # SSH into the VM (uses the VM's pod network)
virtctl scp ./file user@web-01:/tmp -n demo

See Serial Console and Logging into the Virtual Machine using VNC.

Uploading and exporting images

# Upload a local image into a DataVolume (CDI cdi-uploadproxy must be reachable):
virtctl image-upload dv my-image --size=20Gi --storage-class=rbd-1 \
  --image-path=./my-image.qcow2 -n demo

# Export a VM disk or snapshot for download:
virtctl vmexport download my-export --vm=web-01 --output=disk.img.gz -n demo

See Uploading a Local Image and Creating a Virtual Machine for the full local-image upload and virtual-machine creation workflow, and Exporting Virtual Machine Images.

Hot-plugging disks

virtctl addvolume web-01 --volume-name=datadisk-1 --persist -n demo
virtctl removevolume web-01 --volume-name=datadisk-1 -n demo

See Managing Virtual Disks.

Power and migration

virtctl start web-01 -n demo
virtctl stop web-01 -n demo
virtctl restart web-01 -n demo
virtctl pause vm web-01 -n demo        # freeze CPU/memory
virtctl unpause vm web-01 -n demo
virtctl migrate web-01 -n demo         # start a live migration
virtctl migrate-cancel web-01 -n demo  # cancel an in-progress live migration

See Virtual Machine Live Migration and Pausing and Resuming a Virtual Machine.

Editing and sealing images with libguestfs

virtctl guestfs starts an interactive pod with the libguestfs tools attached to a PVC, so you can inspect or modify a disk image offline — for example to reset a machine ID or generalize a template before publishing it as a bootable volume:

virtctl guestfs my-pvc -n demo
# inside the pod:
virt-customize -a /dev/vda --root-password password:'...'
virt-sysprep -a /dev/vda        # generalize (remove host-specific data) before templating