virtctl version
The two primary CLI tools used for managing resources in the cluster are:
The OpenShift Virtualization virtctl
client
The OpenShift Container Platform oc
client
You must install the virtctl
client.
The OpenShift Container Platform oc
client is a command-line utility for managing
OpenShift Container Platform resources, including the VirtualMachine
(vm
) and VirtualMachineInstance
(vmi
) object types.
You can use the |
Command | Description |
---|---|
|
Log in to the OpenShift Container Platform cluster as |
|
Display a list of objects for the specified object type in the current project. |
|
Display details of the specific resource in the current project. |
|
Create a resource in the current project from a file name or from stdin. |
|
Edit a resource in the current project. |
|
Delete a resource in the current project. |
For more comprehensive information on oc
client commands, see the
OpenShift Container Platform CLI tools documentation.
The virtctl
client is a command-line utility for managing OpenShift Virtualization resources.
Command | Description |
---|---|
|
View the |
|
View a list of |
|
View a list of options for a specific command. |
|
View a list of global command options for any |
You can use virtctl
to manage virtual machine (VM) or virtual machine instance (VMI) states and to migrate a VM.
Command | Description |
---|---|
|
Start a VM. |
|
Start a VM in a paused state. This option enables you to interrupt the boot process from the VNC console. |
|
Stop a VM. |
|
Force stop a VM. This option might cause data inconsistency or data loss. |
|
Pause a VM or VMI. The machine state is kept in memory. |
|
Unpause a VM or VMI. |
|
Migrate a VM. |
|
Restart a VM. |
You can use virtctl
to connect to the serial console, expose a port, set a proxy connection, specify a port, and open a VNC connection to a VM.
Command | Description |
---|---|
|
Connect to the serial console of a VMI. |
|
Create a service that forwards a designated port of a VM or VMI and expose the service on the specified port of the node. |
|
Open a Virtual Network Client (VNC) connection to a VMI. Accessing the graphical console of a VMI through VNC requires a remote viewer on your local machine. |
|
Display the port number and connect manually to a VMI by using any viewer through the VNC connection. |
|
Specify a port number to run the proxy on the specified port, if that port is available. If a port number is not specified, the proxy runs on a random port. |
You can use virtctl vmexport
commands to create, download, or delete a volume exported from a VM, VM snapshot, or persistent volume claim (PVC).
Command | Description |
---|---|
|
Create a
|
|
Delete a |
|
Download the volume defined in a
Optional:
|
|
Create a |
You can use the virtctl memory-dump
command to output a virtual machine (VM) memory dump on a PVC. You can specify an existing PVC or use the --create-claim
flag to create a new PVC.
The PVC volume mode must be FileSystem
.
The PVC must be large enough to contain the memory dump.
The formula for calculating the PVC size is (VMMemorySize + 100Mi) * FileSystemOverhead
, where 100Mi
is the memory dump overhead.
You must enable the hot plug feature gate in the HyperConverged
custom resource by running the following command:
$ oc patch hco kubevirt-hyperconverged -n openshift-cnv \
--type json -p '[{"op": "add", "path": "/spec/featureGates", \
"value": "HotplugVolumes"}]'
You must use the virtctl vmexport download
command to download the memory dump:
$ virtctl vmexport download <vmexport_name> --vm\|pvc=<object_name> \
--volume=<volume_name> --output=<output_file>
Command | Description |
---|---|
|
Save the memory dump of a VM on a PVC. The memory dump status is displayed in the Optional:
|
|
Rerun the This command overwrites the previous memory dump. |
|
Remove a memory dump. You must remove a memory dump manually if you want to change the target PVC. This command removes the association between the VM and the PVC, so that the memory dump is not displayed in the |
You can use the virtctl image-upload
commands to upload a VM image to a data volume.
Command | Description |
---|---|
|
Upload a VM image to a data volume that already exists. |
|
Upload a VM image to a new data volume of a specified requested size. |
You can use virtctl
to view information about versions, file systems, guest operating systems, and logged-in users.
Command | Description |
---|---|
|
View the file systems available on a guest machine. |
|
View information about the operating systems on a guest machine. |
|
View the logged-in users on a guest machine. |
You can use the virtctl guestfs
command to deploy an interactive container with libguestfs-tools
and a persistent volume claim (PVC) attached to it.
To deploy a container with libguestfs-tools
, mount the PVC, and attach a shell to it, run the following command:
$ virtctl guestfs -n <namespace> <pvc_name> (1)
1 | The PVC name is a required argument. If you do not include it, an error message appears. |
Libguestfs
tools help you access and modify virtual machine (VM) disk images. You can use libguestfs
tools to view and edit files in a guest, clone and build virtual machines, and format and resize disks.
You can also use the virtctl guestfs
command and its sub-commands to modify, inspect, and debug VM disks on a PVC. To see a complete list of possible sub-commands, enter virt-
on the command line and press the Tab key. For example:
Command | Description |
---|---|
|
Edit a file interactively in your terminal. |
|
Inject an ssh key into the guest and create a login. |
|
See how much disk space is used by a VM. |
|
See the full list of all RPMs installed on a guest by creating an output file containing the full list. |
|
Display the output file list of all RPMs created using the |
|
Seal a virtual machine disk image to be used as a template. |
By default, virtctl guestfs
creates a session with everything needed to manage a VM disk. However, the command also supports several flag options if you want to customize the behavior:
Flag Option | Description |
---|---|
|
Provides help for |
|
To use a PVC from a specific namespace. If you do not use the If you do not include a |
|
Lists the You can configure the container to use a custom image by using the |
|
Indicates that By default, If a cluster does not have any If not set, the |
|
Shows the pull policy for the You can also overwrite the image’s pull policy by setting the |
The command also checks if a PVC is in use by another pod, in which case an error message appears. However, once the libguestfs-tools
process starts, the setup cannot avoid a new pod using the same PVC. You must verify that there are no active virtctl guestfs
pods before starting the VM that accesses the same PVC.
The |