// Module included in the following assemblies:
//
// * hosted_control_planes/hcp-manage/hcp-manage-virt.adoc

:_mod-docs-content-type: PROCEDURE
[id="hcp-virt-evict-vms_{context}"]
= Evicting KubeVirt virtual machines

[role="_abstract"]
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 {VirtProductName} 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. 

.Procedure

. To learn more about the `hyperconverged` resource and the allowed values for the `evictionStrategy` parameter, enter the following command:
+
[source,terminal]
----
$ oc explain hyperconverged.spec.virtualization.evictionStrategy
----

. Patch the `hyperconverged` resource by entering the following command:
+
[source,terminal,subs="attributes+"]
----
$ oc patch -n {CNVNamespace} {HCOCliKind} kubevirt-hyperconverged \
  --type=merge \
  -p '{"spec": {"virtualization": {"evictionStrategy": "External"}}}'
----

. Patch the workload update strategy and the workload update methods by entering the following command:
+
[source,terminal,subs="attributes+"]
----
$ oc patch -n {CNVNamespace} {HCOCliKind} 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.

.Verification

* Check whether the patch command was applied properly by entering the following command:
+
[source,terminal,subs="attributes+"]
----
$ oc get -n {CNVNamespace} {HCOCliKind} kubevirt-hyperconverged -ojsonpath='{.spec.virtualization.evictionStrategy}'
----
+
.Example output
[source,terminal]
----
External
----