Updated on 2025-04-27 GMT+08:00

Managing VMs

  • Starting a VM
    1. Run the following virtctl command to start a VM:
       virtctl start testvm
      You will see the following output:
       VM testvm was scheduled to start
    2. Wait for several minutes and run the following kubectl command to check the VM status:
       kubectl get vm
      Example output:
      NAME     AGE   STATUS    READY
      testvm   2h   Running   True
  • Listing VMs

    You can list the VMs in all namespaces and their statuses, or only the VMs in a namespace.

    • Run the following command to list the VMs in all namespaces:
       kubectl get vm -A
      Example output:
      NAMESPACE    NAME        AGE   STATUS    READY
      default      testvm      82m   Running   True
      my-vm-pool   vm-cirros   64s   Running   True
    • Run the following command to list the VMs in a namespace:
      kubectl get vm -n my-vm-pool
      Example output:
      NAME        AGE     STATUS    READY
      vm-cirros   2m14s   Running   True
  • Viewing VM Information
    • View basic VM information.
      kubectl get vmi -n my-vm-pool
      The output shows basic information such as the IP address assigned to the VM.
      NAME     AGE   PHASE     IP              NODENAME        READY
      testvm   91m   Running   172.16.51.103   192.168.88.99   True
    • For more details, run the following ubectl describe commands:
      kubectl describe vm/testvm
      kubectl describe vmi/testvm
  • Stoping a VM

    Run the following command:

    virtctl stop testvm
  • Restarting a VM

    Run the following command:

    virtctl restart testvm
  • Deleting a VM
    Running the following command to delete a VM and its associated resources:
    kubectl delete -f "https://kubevirt.io/labs/manifests/vm.yaml"
    Example output:
    virtualmachine.kubevirt.io "testvm" deleted