Configuring live migration
You can configure live migration settings to ensure that the migration processes do not overwhelm the cluster. You can configure live migration policies to apply different migration configurations to groups of virtual machines (VMs).
Configuring live migration limits and timeouts
Configure live migration limits and timeouts for the cluster by updating the HyperConverged custom resource (CR), which is located in the openshift-cnv namespace.
Prerequisites
- You have installed the OpenShift CLI (
oc).
Procedure
-
Edit the
HyperConvergedCR and add the necessary live migration parameters:$ oc edit hyperconvergeds.v1beta1.hco.kubevirt.io kubevirt-hyperconverged -n openshift-cnvExample configuration file:
apiVersion: hco.kubevirt.io/v1beta1kind: HyperConvergedmetadata:name: kubevirt-hyperconvergednamespace: openshift-cnvspec:liveMigrationConfig:bandwidthPerMigration: 2048MicompletionTimeoutPerGiB: 800parallelMigrationsPerCluster: 5parallelOutboundMigrationsPerNode: 2progressTimeout: 150allowPostCopy: falsewhere:
bandwidthPerMigration- Specifies the bandwidth of each migration in bytes per second. For example, a value of 2048Mi means 2048 MiB/s. Default: 0, which is unlimited.
completionTimeoutPerGiB- Specifies the length of time, in seconds per GiB of memory, at which the migration is canceled if it has not completed. For example, a VM with 6GiB memory times out if it has not completed migration in 4800 seconds. If the
Migration MethodisBlockMigration, the size of the migrating disks is included in the calculation. parallelMigrationsPerCluster- Specifies the number of migrations running in parallel in the cluster. Default:
5. parallelOutboundMigrationsPerNode- Specifies the maximum number of outbound migrations per node. Default:
2. progressTimeout- Specifies the length of time, in seconds, at which the migration is canceled if memory copy fails to make progress. Default:
150. allowPostCopy- Specifies whether the post copy mode is enabled. You can enable post copy mode to allow the migration of one node to another to converge, even if a VM is running a heavy workload and the memory dirty rate is too high. By default,
allowPostCopyis set tofalse.
noteYou can restore the default value for any
spec.liveMigrationConfigfield by deleting that key/value pair and saving the file. For example, deleteprogressTimeout: <value>to restore the defaultprogressTimeout: 150.
Configure live migration for heavy workloads
When migrating a VM running a heavy workload, such as database processing, higher memory dirty rates can prevent the migration from completing. To address this, you can enable post copy mode, which allows the migration to complete when the pre-copy phase cannot converge.
Configure live migration for heavy workloads by updating the HyperConverged custom resource (CR) in the openshift-cnv namespace.
Prerequisites
- You have installed the OpenShift CLI (
oc).
Procedure
-
Edit the
HyperConvergedCR and add the necessary parameters for migrating heavy workloads:$ oc edit hyperconvergeds.v1beta1.hco.kubevirt.io kubevirt-hyperconverged -n openshift-cnvExample configuration file:
apiVersion: hco.kubevirt.io/v1beta1kind: HyperConvergedmetadata:name: kubevirt-hyperconvergednamespace: openshift-cnvspec:liveMigrationConfig:bandwidthPerMigration: 0MicompletionTimeoutPerGiB: 150parallelMigrationsPerCluster: 5parallelOutboundMigrationsPerNode: 1progressTimeout: 150allowPostCopy: truewhere:
bandwidthPerMigration- Specifies the bandwidth of each migration in bytes per second. The default is
0, which is unlimited. completionTimeoutPerGiB- Specifies the length of time, in seconds per GiB of memory, at which the migration is canceled if it has not completed and post copy mode is triggered, if enabled. You can lower
completionTimeoutPerGiBto trigger post copy mode earlier in the migration process, or raise thecompletionTimeoutPerGiBto trigger post copy mode later in the migration process. parallelMigrationsPerCluster- Specifies the number of migrations running in parallel in the cluster. The default is
5. Keeping theparallelMigrationsPerClustersetting low is better when migrating heavy workloads. parallelOutboundMigrationsPerNode- Specifies the maximum number of outbound migrations per node. Configure a single VM per node for heavy workloads.
progressTimeout- Specifies the length of time, in seconds, at which the migration is canceled if memory copy fails to make progress. Increase this parameter for large memory sizes running heavy workloads.
allowPostCopy- Specifies whether the post copy mode is enabled. You can enable post copy mode to allow the migration of one node to another to converge, even if a VM is running a heavy workload and the memory dirty rate is too high. Set allowPostCopy to true to enable post copy mode.
-
Optional: If your main network is too busy for the migration, configure a secondary, dedicated migration network.
notePost copy mode can impact performance during the transfer, and should not be used for critical data, or with unstable networks.
Live migration policies
You can create live migration policies to apply different migration configurations to groups of VMs that are defined by VM or project labels.
You can create live migration policies by using the OpenShift Container Platform web console.
Creating a live migration policy by using the CLI
You can create a live migration policy by using the command line.
KubeVirt applies the live migration policy to selected virtual machines (VMs) by using any combination of labels:
- VM labels such as
size,os, orgpu - Project labels such as
priority,bandwidth, orhpc-workload
For the policy to apply to a specific group of VMs, all labels on the group of VMs must match the labels of the policy.
If multiple live migration policies apply to a VM, the policy with the greatest number of matching labels takes precedence.
If multiple policies meet this criteria, the policies are sorted by alphabetical order of the matching label keys, and the first one in that order takes precedence.
Prerequisites
- You have installed the OpenShift CLI (
oc).
Procedure
-
Edit the VM object to which you want to apply a live migration policy, and add the corresponding VM labels.
- Open the YAML configuration of the resource:
$ oc edit vm <vm_name>
- Adjust the required label values in the
.spec.template.metadata.labelssection of the configuration. For example, to mark the VM as aproductionVM for the purposes of migration policies, add thekubevirt.io/environment: productionline:apiVersion: migrations.kubevirt.io/v1alpha1kind: VirtualMachinemetadata:name: <vm_name>namespace: defaultlabels:app: my-appenvironment: productionspec:template:metadata:labels:kubevirt.io/domain: <vm_name>kubevirt.io/size: largekubevirt.io/environment: production# ... - Save and exit the configuration.
- Open the YAML configuration of the resource:
-
Configure a
MigrationPolicyobject with the corresponding labels. The following example configures a policy that applies to all VMs that are labeled asproduction:apiVersion: migrations.kubevirt.io/v1alpha1kind: MigrationPolicymetadata:name: <migration_policy>spec:selectors:namespaceSelector:hpc-workloads: "True"xyz-workloads-type: ""virtualMachineInstanceSelector:kubevirt.io/environment: "production"where:
namespaceSelector- Specifies the project labels.
virtualMachineInstanceSelector- Specifies the VM labels.
-
Create the migration policy by running the following command:
$ oc create -f <migration_policy>.yaml
Additional resources