// Module included in the following assemblies:
//
// * virt/about_virt/virt-vm-recovery-from-node-failures.adoc
:_mod-docs-content-type: PROCEDURE
[id="virt-configuring-node-health-checks-for-vms_{context}"]
= Configuring node health checks for virtual machines

[role="_abstract"]
You can configure the Node Health Check Operator to monitor node status and trigger automated remediation when a node becomes unhealthy.

.Prerequisites

* You have installed the Node Health Check Operator.
* You have installed a remediation operator.
* You have cluster administrator privileges.

.Procedure

. Create a `NodeHealthCheck` custom resource (CR) to define the health check criteria and remediation strategy:
+
[source,yaml]
----
apiVersion: remediation.medik8s.io/v1alpha1
kind: NodeHealthCheck
metadata:
  name: nodehealthcheck-sample
spec:
  minHealthy: <count>
  pauseRequests:
    - <pause_test_cluster>
  remediationTemplate:
    apiVersion: self-node-remediation.medik8s.io/v1alpha1
    name: self-node-remediation-automatic-strategy-template
    namespace: openshift-workload-availability
    kind: SelfNodeRemediationTemplate
  escalatingRemediations:
    - remediationTemplate:
        apiVersion: self-node-remediation.medik8s.io/v1alpha1
        name: self-node-remediation-resource-deletion-template
        namespace: openshift-workload-availability
        kind: SelfNodeRemediationTemplate
      order: 1
      timeout: 300s
  selector:
    matchExpressions:
      - key: node-role.kubernetes.io/worker
        operator: Exists
  unhealthyConditions:
    - type: Ready
      status: "False"
      duration: 30s
    - type: Ready
      status: Unknown
      duration: 30s
----
+
where:
+
* `spec.minHealthy` defines the number of worker nodes required to host VMs that migrate from failed nodes.
** For critical environments, set this value to the minimum number of nodes that you require to maintain the cluster workload.
** For hyperconverged storage, set this value to one less than your number of nodes to limit remediation to a single worker-node failure and maintain storage stability.
* `spec.remediationTemplate` defines the remediation template to use when the Node Health Check Operator detects an unhealthy node. This example uses the Self Node Remediation Operator.
* `spec.escalatingRemediations` defines escalating remediation strategies. If the initial remediation does not resolve the issue within the specified timeout, the next remediation strategy runs.
* `spec.selector` defines the nodes to monitor. This example monitors all worker nodes.
* `spec.unhealthyConditions` defines the parameters to identify an unhealthy node.
* `spec.unhealthyConditions.duration` defines the duration that a condition must persist before remediation starts. Set lower values for faster recovery. The following table shows recommended values:
+
.Recommended `unhealthyConditions` duration values
[cols="1,1",options="header"]
|===
|Environment
|Recommended duration

|Critical
|30-60 seconds

|Standard
|60-180 seconds

|Conservative
|180-360 seconds
|===

. Apply the `NodeHealthCheck` CR by running the following command:
+
[source,terminal]
----
$ oc apply -f nodehealthcheck-sample.yaml
----

.Verification

* Verify that the `NodeHealthCheck` CR exists by running the following command:
+
[source,terminal]
----
$ oc get nodehealthcheck nodehealthcheck-sample
----

[TIP]
====
If remediation does not trigger as expected, verify that the remediation Operator runs correctly, and check the `NodeHealthCheck` CR events for errors:

[source,terminal]
----
$ oc describe nodehealthcheck nodehealthcheck-sample
----
====
