Bookmark this page

Guided Exercise: Perform Virtual Machine Live Migrations

Live migrate a VM to another node in the cluster.

Outcomes

  • Observe and set the access mode for a storage profile.

  • Initiate a live migration through the web console and command line.

  • Monitor the progress of live migrations.

  • Cancel a live migration through the web console and command line.

As the student user on the workstation machine, use the lab command to prepare your environment for this exercise, and to ensure that all required resources are available.

[student@workstation ~]$ lab start advanced-migrate

Instructions

  1. As the admin user, confirm that the vm1 VM is running on the advanced-migrate project.

    1. Open a command-line window and log in to the OpenShift cluster as the admin user with redhatocp as the password.

      [student@workstation ~]$ oc login -u admin -p redhatocp \
        https://api.ocp4.example.com:6443
      Login Successful
      ...output omitted...
    2. Identify the URL for the OpenShift web console.

      [student@workstation ~]$ oc whoami --show-console
        https://console-openshift-console.apps.ocp4.example.com
    3. Open a web browser and navigate to https://console-openshift-console.apps.ocp4.example.com. Click htpasswd_provider and log in as the admin user with redhatocp as the password.

    4. Navigate to VirtualizationVirtualMachines. Select the advanced-migrate project from the Project list. Confirm that the vm1 VM is running.

  2. Confirm that the vm1 VM is not migratable. Determine the storage class of the VM's empty tempdata disk.

    1. Click the vertical ellipsis icon at the right of the vm1 VM and then confirm that Migrate is disabled.

      The Status and Conditions columns show the Not migratable and LiveMigratable=False values for the vm1 VM.

      The live migration is not available because the empty tempdata PersistentVolumeClaim (PVC) is not configured with a ReadWriteMany access mode.

    2. Identify the storage class for the tempdata disk. Select the vm1 VM. Navigate to the Configuration tab. In the Disks section, notice that the tempdata disk uses the nfs-storage storage class.

  3. Retrieve the current default storage class settings for Red Hat OpenShift Virtualization. Configure the nfs-storage storage class to use ReadWriteMany access mode.

    1. From a command-line, execute the oc describe command to retrieve the nfs-storage storage profile. Notice that the nfs-storage storage class defaults to a ReadWriteOnce access mode.

      [student@workstation ~]$ oc describe storageprofile nfs-storage
      ...output omitted...
      Spec:
        Claim Property Sets:
          Access Modes:
            ReadWriteOnce
          Volume Mode:  Filesystem
      ...output omitted...
    2. Change the nfs-storage access mode to ReadWriteMany by using the oc edit command.

      You can copy and then paste the command from the ~/DO316/labs/advanced-migrate/commands.txt file.

      [student@workstation ~]$ oc edit storageprofile nfs-storage
      ...output omitted...
      spec:
        claimPropertySets:
        - accessModes:
          - ReadWriteMany
          volumeMode: FileSystem
      ...output omitted...
    3. Confirm that the nfs-storage storage profile is updated with the correct access mode.

      [student@workstation ~]$ oc describe storageprofile nfs-storage
      ...output omitted...
      Spec:
        Claim Property Sets:
          Access Modes:
            ReadWriteMany
          Volume Mode:  Filesystem
      ...output omitted...
  4. Delete the empty tempdata disk from the vm1 VM. Attach a new 2 GiB blank disk named newtempdata that uses the nfs-storage storage class.

    1. You must stop the vm1 VM before you can modify the VM's disks. In the OpenShift web console, navigate to VirtualizationVirtualMachines. Select the vm1 VM and then click ActionsStop. Wait for the VM to stop.

    2. Navigate to the Configuration tab. In the Disks section, click the vertical ellipsis icon at the right of the tempdata disk and then click Detach. Click Detach to confirm the operation.

    3. Click Add disk to create a disk. Select Blank (creates PVC) as the source and then enter newtempdata for the name.

      Set the Size field to 2 GiB value and leave the virtio value for the Interface field. Confirm that the StorageClass field is set to the nfs-storage value, and that the Access Mode field is set to the Shared access (RWX) value. Clear Apply optimized StorageProfile settings and click Save to add the disk.

    4. Click ActionsStart to power on the VM. Wait a few moments for the operation to complete.

  5. Live migrate the vm1 VM in the OpenShift web console. Afterwards, initiate and then cancel another live migration for the VM.

    1. In the web console, navigate to VirtualizationVirtualMachines. The Node column shows the compute node for the vm1 VM. Make note of the compute node that is hosting the VM.

    2. Click the vertical ellipsis icon at the right of the vm1 VM and then click Migrate. Wait a few moments for the migration to complete.

    3. Confirm that the Node column shows a different compute node for the vm1 VM than identified in an earlier step.

    4. Initiate another live migration for the VM. Click the vertical ellipsis icon at the right of the vm1 VM and then click Migrate.

    5. Cancel the live migration. Click the vertical ellipsis icon at the right of the vm1 VM and then click Cancel migration.

  6. Initiate another live migration for the vm1 VM by using a VirtualMachineInstanceMigration manifest.

    1. In a text editor, modify the migrate-vmi.yml file in the ~/DO316/labs/advanced-migrate/ directory.

      apiVersion: kubevirt.io/v1
      kind: VirtualMachineInstanceMigration
      metadata:
        name: vm1-migration-job
      spec:
        vmiName: vm1
    2. In the terminal, use the oc create command to initiate the live migration with the migrate-vmi.yml manifest.

      [student@workstation ~]$ oc create -f \
        ~/DO316/labs/advanced-migrate/migrate-vmi.yml -n advanced-migrate
      virtualmachineinstancemigration.kubevirt.io/vm1-migration-job created
    3. Monitor the live migration with the oc describe vmi command. Confirm that vm1 is migrated to another node and make note of the node's name. You might have to wait a few minutes and rerun the command several times.

      [student@workstation ~]$ oc describe vmi vm1 -n advanced-migrate
      ...output omitted...
      Events:
        Type    Reason          Age   From          Message
        ----    ------          ----  ----          -------
      ...output omitted...
        Normal   SuccessfulUpdate  119s   virtualmachine-controller    Expanded PodDisruptionBudget kubevirt-disruption-budget-8dg2q
        Normal   Migrating         84s (x2 over 7m23s)    virt-handler                 VirtualMachineInstance is migrating.
        Normal   PreparingTarget   84s (x4 over 7m23s)    virt-handler                 VirtualMachineInstance Migration Target Prepared.
        Normal   PreparingTarget   84s    virt-handler                 Migration Target is listening at 10.8.2.35, on ports: 39015,38699,40715
        Normal   Migrated          81s    virt-handler                 The VirtualMachineInstance migrated to node worker02.
        Normal   Deleted           81s    virt-handler                 Signaled Deletion
        Normal   SuccessfulUpdate  77s    disruptionbudget-controller  shrank PodDisruptionBudget kubevirt-disruption-budget-8dg2q
  7. Use the command line to initiate and then cancel a live migration for the vm1 VM.

    1. In your terminal, delete the previous vm1-migration-job with the oc delete vmim command.

      [student@workstation ~]$ oc delete vmim vm1-migration-job -n advanced-migrate
      virtualmachineinstancemigration.kubevirt.io "vm1-migration-job" deleted
    2. Use the oc create command to initiate a live migration with the migrate-vmi.yml file.

      [student@workstation ~]$ oc create \
        -f ~/DO316/labs/advanced-migrate/migrate-vmi.yml -n advanced-migrate
      virtualmachineinstancemigration.kubevirt.io/vm1-migration-job created
    3. Cancel the live migration by deleting the VirtualMachineInstanceMigration object.

      [student@workstation ~]$ oc delete vmim vm1-migration-job -n advanced-migrate
      virtualmachineinstancemigration.kubevirt.io "vm1-migration-job" deleted
    4. Confirm that the VM is not migrated to another node.

      [student@workstation ~]$ oc describe vmi vm1 -n advanced-migrate
      ...output omitted...
      Events:
        Type     Reason          Age   From          Message
        ----     ------          ----  ----          -------
      ...output omitted...
        Normal   Migrating       10s   virt-handler  VirtualMachineInstance is migrating.
        Normal   PreparingTarget 10s   virt-handler  VirtualMachineInstance Migration Target Prepared.
        Normal   PreparingTarget 10s   virt-handler  Migration Target is listening at 10.8.2.7, on ports: 43169,35525,40499
        Normal   Migrating       10s   virt-handler  VirtualMachineInstance is aborting migration.
        ...output omitted...
  8. Close the web browser.

Finish

On the workstation machine, use the lab command to complete this exercise. This step is important to ensure that resources from previous exercises do not impact upcoming exercises.

[student@workstation ~]$ lab finish advanced-migrate

Revision: do316-4.14-d8a6b80