VM Import

Available as of v1.1.0

Beginning with v1.1.0, users can import their virtual machines from VMWare and OpenStack into Harvester.

This is accomplished using the vm-import-controller addon.

To use the VM Import feature, users need to enable the vm-import-controller addon.

VM Import - 图1

By default, vm-import-controller leverages ephemeral storage, which is mounted from /var/lib/kubelet.

During the migration, a large VM’s node could run out of space on this mount, resulting in subsequent scheduling failures.

To avoid this, users are advised to enable PVC-backed storage and customize the amount of storage needed. According to the best practice, the PVC size should be twice the size of the largest VM being migrated. This is essential as the PVC is used as scratch space to download the VM, and convert the disks into raw image files.

VM Import - 图2

vm-import-controller

Currently, the following source providers are supported:

  • VMWare
  • OpenStack

API

The vm-import-controller introduces two CRDs.

Sources

Sources allow users to define valid source clusters.

For example:

  1. apiVersion: migration.harvesterhci.io/v1beta1
  2. kind: VmwareSource
  3. metadata:
  4. name: vcsim
  5. namespace: default
  6. spec:
  7. endpoint: "https://vscim/sdk"
  8. dc: "DCO"
  9. credentials:
  10. name: vsphere-credentials
  11. namespace: default

The secret contains the credentials for the vCenter endpoint:

  1. apiVersion: v1
  2. kind: Secret
  3. metadata:
  4. name: vsphere-credentials
  5. namespace: default
  6. stringData:
  7. "username": "user"
  8. "password": "password"

As part of the reconciliation process, the controller will log into vCenter and verify whether the dc specified in the source spec is valid.

Once this check is passed, the source is marked as ready and can be used for VM migrations.

  1. $ kubectl get vmwaresource.migration
  2. NAME STATUS
  3. vcsim clusterReady

For OpenStack-based source clusters, an example definition is as follows:

  1. apiVersion: migration.harvesterhci.io/v1beta1
  2. kind: OpenstackSource
  3. metadata:
  4. name: devstack
  5. namespace: default
  6. spec:
  7. endpoint: "https://devstack/identity"
  8. region: "RegionOne"
  9. credentials:
  10. name: devstack-credentials
  11. namespace: default

The secret contains the credentials for the OpenStack endpoint:

  1. apiVersion: v1
  2. kind: Secret
  3. metadata:
  4. name: devstack-credentials
  5. namespace: default
  6. stringData:
  7. "username": "user"
  8. "password": "password"
  9. "project_name": "admin"
  10. "domain_name": "default"
  11. "ca_cert": "pem-encoded-ca-cert"

The OpenStack source reconciliation process attempts to list VMs in the project and marks the source as ready.

  1. $ kubectl get opestacksource.migration
  2. NAME STATUS
  3. devstack clusterReady

VirtualMachineImport

The VirtualMachineImport CRD provides a way for users to define a source VM and map to the actual source cluster to perform VM export/import.

A sample VirtualMachineImport looks like this:

  1. apiVersion: migration.harvesterhci.io/v1beta1
  2. kind: VirtualMachineImport
  3. metadata:
  4. name: alpine-export-test
  5. namespace: default
  6. spec:
  7. virtualMachineName: "alpine-export-test"
  8. networkMapping:
  9. - sourceNetwork: "dvSwitch 1"
  10. destinationNetwork: "default/vlan1"
  11. - sourceNetwork: "dvSwitch 2"
  12. destinationNetwork: "default/vlan2"
  13. sourceCluster:
  14. name: vcsim
  15. namespace: default
  16. kind: VmwareSource
  17. apiVersion: migration.harvesterhci.io/v1beta1

This will trigger the controller to export the VM named “alpine-export-test” on the VMWare source cluster to be exported, processed and recreated into the harvester cluster

This can take a while based on the size of the virtual machine, but users should see VirtualMachineImages created for each disk in the defined virtual machine.

The list of items in networkMapping will define how the source network interfaces are mapped to the Harvester Networks.

If a match is not found, each unmatched network interface is attached to the default managementNetwork.

Once the virtual machine has been imported successfully, the object will reflect the status:

  1. $ kubectl get virtualmachineimport.migration
  2. NAME STATUS
  3. alpine-export-test virtualMachineRunning
  4. openstack-cirros-test virtualMachineRunning

Similarly, users can define a VirtualMachineImport for an OpenStack source as well:

  1. apiVersion: migration.harvesterhci.io/v1beta1
  2. kind: VirtualMachineImport
  3. metadata:
  4. name: openstack-demo
  5. namespace: default
  6. spec:
  7. virtualMachineName: "openstack-demo" #Name or UUID for instance
  8. networkMapping:
  9. - sourceNetwork: "shared"
  10. destinationNetwork: "default/vlan1"
  11. - sourceNetwork: "public"
  12. destinationNetwork: "default/vlan2"
  13. sourceCluster:
  14. name: devstack
  15. namespace: default
  16. kind: OpenstackSource
  17. apiVersion: migration.harvesterhci.io/v1beta1

VM Import - 图3备注

OpenStack allows users to have multiple instances with the same name. In such a scenario, users are advised to use the Instance ID. The reconciliation logic tries to perform a name-to-ID lookup when a name is used.