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

Getting Started with VM Runtime

In this part, you will know how to use kubectl to create a VM using a public image and default credentials. You will also know how to connect to the VM after it is created and delete it when you no longer need it.

  1. Create a VM.

    Create a VM in the cluster. The virtctl add-on is used together with the kubectl command. Run the following command to create a VM that uses the CirrOS image. By default, the VM uses the default storage class and has two vCPUs, 4-GiB memory, and a 20-GiB boot disk in ReadWriteOnce mode.

    virtctl create vm --name VM_NAME --volume-containerdisk src:quay.io/kubevirt/cirros-container-disk-demo:latest --memory "4Gi" | kubectl create -f -

    Configure VM_NAME as follows:

    • VM_NAME: Enter up to 63 characters. Start and end with a lowercase letter or digit. Only lowercase letters, digits, and hyphens (-) are allowed.

      The following is an example:

      1. Create a VM named testvm.
        virtctl create vm --name testvm --volume-containerdisk src:quay.io/kubevirt/cirros-container-disk-demo:latest --memory "4Gi" | kubectl create -f –
      2. Wait for a while and run the following command to check the VM status:
        kubectl get vm
        The following example output shows that the VM is in the Running state:
        NAME     AGE   STATUS    READY
        testvm   54s   Running   True

  2. Connect to the VM.

    Access the VM console when the VM is running.

    1. To access a VM through the console, run the following virtctl command:
      virtctl console testvm
      You will see the following information:
      Successfully connected to testvm console. The escape sequence is ^]
    2. Press Enter. The following information is displayed:
      login as 'cirros' user. default password: 'gocubsgo'. use 'sudo' for root.
      login:
    3. Enter the username and password, for example, cirros and gocubsgo.
      After the VM console is successfully connected, exit the VM session and console.
      Ctrl + ]

  3. Delete the VM and its associated DataVolume.

     kubectl delete vm testvm