Evicting KubeVirt virtual machines
In cases where KubeVirt virtual machines (VMs) cannot be live migrated, such as when you use GPU passthrough, the VMs must be evicted at the same time as the NodePool resource of the hosted cluster.
Otherwise, the compute nodes might be shut down without being drained from the workload. This might also happen when you are upgrading the OpenShift Virtualization Operator.
To achieve a synchronized restart, you can set the evictionStrategy parameter on the hyperconverged resource to ensure that only VMs that are drained from workloads are rebooted.
-
To learn more about the
hyperconvergedresource and the allowed values for theevictionStrategyparameter, enter the following command:$ oc explain hyperconverged.spec.virtualization.evictionStrategy -
Patch the
hyperconvergedresource by entering the following command:$ oc patch -n openshift-cnv hco kubevirt-hyperconverged \ --type=merge \ -p '{"spec": {"virtualization": {"evictionStrategy": "External"}}}' -
Patch the workload update strategy and the workload update methods by entering the following command:
$ oc patch -n openshift-cnv hco kubevirt-hyperconverged \ --type=merge \ -p '{"spec": {"virtualization": {"workloadUpdateStrategy": {"workloadUpdateMethods": ["LiveMigrate","Evict"]}}}}'By applying this patch, you specify that VMs should be live-migrated if possible, and that only the VMs that cannot be live-migrated should be evicted.
-
Check whether the patch command was applied properly by entering the following command:
$ oc get -n openshift-cnv hco kubevirt-hyperconverged -ojsonpath='{.spec.virtualization.evictionStrategy}'Example outputExternal