After you create an AI-optimized Google Kubernetes Engine (GKE) cluster, you can
enable *node health prediction* . If you plan to
[schedule workloads by using Topology Aware Scheduling (TAS) and Kueue](https://docs.cloud.google.com/ai-hypercomputer/docs/workloads/schedule-gke-workloads-tas.md.txt),
then enabling node health prediction lets the cluster's scheduler do the
following:

1. Identify nodes that are likely to degrade within the next five hours.

2. Avoid scheduling new workloads on those nodes.

This approach helps you minimize interruptions on critical and
interruption-sensitive workloads, such as large-scale training workloads.

This document explains how to enable node health prediction in a
GKE cluster that uses [General GPU machine series](https://docs.cloud.google.com/ai-hypercomputer/docs/evaluate-general-gpus.md.txt) (A3 Edge, A2, G2, G4, N1) or [Clustered GPU machine series](https://docs.cloud.google.com/ai-hypercomputer/docs/cluster-capabilities.md.txt) (A4X Max, A4X, A4, A3 Ultra, A3 Mega, and A3 High) nodes. To learn how to
use the node health prediction metric in a Cloud Monitoring dashboard when,
for example, you want to troubleshoot performance issues on a Slurm cluster, see
instead
[Monitor Compute Engine instances and Slurm clusters](https://docs.cloud.google.com/ai-hypercomputer/docs/monitor.md.txt).

## Limitations

Before you enable node health prediction in your GKE cluster,
consider the following limitations:

- The node must use General GPU (A3 Edge, A2, G2, G4, N1) or Clustered GPU (A4X Max, A4X, A4, A3 Ultra, A3 Mega, A3 High) machine types.

- The node must use the
  [reservation-bound provisioning model](https://docs.cloud.google.com/ai-hypercomputer/docs/create/review-configurations.md.txt#reservation-bound).

  > [!NOTE]
  > **Note:** If the nodes in your cluster use an A3 Mega or A3 High machine type, or you created the nodes by using a different provisioning model, then contact your account team.

## Understand node health prediction

When you enable node health prediction in a GKE cluster, the
CronJob applies the `gke.google.com/recommended-to-run-large-training-workload`
label to each node in your cluster. The CronJob sets the label values to the
likelihood that a node's GPU health will degrade, and updates these values every
10 minutes. If the label value is `true`, then the node is healthy. Otherwise,
if the label value is `false`, the node will likely degrade within the next five
hours. The label value can change over time based on the node's GPU health.

If you see that a node is likely to degrade, then you can do one or both of the
following:

- **Avoid scheduling workloads on the node** . You can configure Kueue to avoid
  scheduling workloads on nodes that show a value of `false`, as described in
  this document.

- **Report the node as faulty** . If the node is experiencing issues like high
  GPU temperature or slow performance, then you can report the node as faulty.
  This action starts a host maintenance event for the node, making it
  available again for running workloads after maintenance completes. For
  instructions, see
  [Report faulty hosts through GKE](https://docs.cloud.google.com/ai-hypercomputer/docs/manage/manage-gke-clusters.md.txt#report-faulty-hosts).

## Before you begin


Before you start, make sure that you have performed the following tasks:

- Enable the Google Kubernetes Engine API.
[Enable Google Kubernetes Engine API](https://console.cloud.google.com/apis/enableflow?apiid=container.googleapis.com)
- To use the Google Cloud CLI for this task, [install](https://docs.cloud.google.com/sdk/docs/install) and then [initialize](https://docs.cloud.google.com/sdk/docs/initialize.md.txt) the gcloud CLI. If you previously installed the gcloud CLI, get the latest version by running the `gcloud components update` command. Earlier gcloud CLI versions might not support running the commands in this document.

  > [!NOTE]
  > **Note:** For existing gcloud CLI installations, make sure to set the `compute/region` [property](https://docs.cloud.google.com/sdk/docs/properties.md.txt#setting_properties). If you use primarily zonal clusters, set the `compute/zone` instead. By setting a default location, you can avoid errors in the gcloud CLI like the following: `One of [--zone, --region] must be supplied: Please specify location`. You might need to specify the location in certain commands if the location of your cluster differs from the default that you set.

<!-- -->

- To connect to your cluster, run the following command:

  ```bash
  gcloud container clusters get-credentials CLUSTER_NAME
  ```

  Replace `CLUSTER_NAME` with the name of your cluster.

## Enable node health prediction

After you've prepared to schedule workloads on your GKE cluster
by using TAS, you can enable node health prediction by completing the following
steps:

1. [Deploy automatic node labeling](https://docs.cloud.google.com/ai-hypercomputer/docs/workloads/enable-node-health-prediction.md.txt#node-labeling)

2. [Update your Job configuration](https://docs.cloud.google.com/ai-hypercomputer/docs/workloads/enable-node-health-prediction.md.txt#configure)

3. [Verify node labeling](https://docs.cloud.google.com/ai-hypercomputer/docs/workloads/enable-node-health-prediction.md.txt#verify)

### Deploy automatic node labeling

To deploy automatic node labeling for node health prediction in your
GKE cluster, complete the following steps:

1. Clone the hardware accelerators in GKE git repository:

   ```bash
   git clone https://github.com/GoogleCloudPlatform/container-engine-accelerators.git
   ```
2. Go to the `topology-scheduler` directory:

   ```bash
   cd container-engine-accelerators/gpudirect-tcpxo/topology-scheduler
   ```
3. Create the Kubernetes ConfigMap containing the Python scripts,
   `schedule-daemon.py` and `label-nodes-daemon.py`, that query the health
   scores:

   > [!NOTE]
   > **Note:** These scripts query health prediction scores for both manually installed driver environments and managed driver installations (such as when using the `gpu-driver-version=LATEST` flag).

   ```bash
   kubectl create configmap predictor-scheduler-scripts \
       --namespace=kube-system \
       --from-file=schedule-daemon.py=schedule-daemon.py \
       --from-file=label-nodes-daemon.py=label-nodes-daemon.py
   ```
4. Apply the service account configuration to grant the necessary permissions
   (reading Monitoring metrics and patching Node objects) to the CronJob:

   ```bash
   kubectl apply -f service-account.yaml
   ```
5. Deploy the DaemonSet that schedules the node labeling job:

   ```bash
   kubectl apply -f label-nodes-daemon.yaml
   ```

### Update your Job configuration

To enable node health prediction when using Kueue, you must update your Job
configuration to check for health prediction values and, if supported, topology
requirements before starting a workload.

To update your Job configuration and enable node health prediction, in the
`spec` field, add the following fields:

```yaml
spec:
  affinity:
    nodeAffinity:
      requiredDuringSchedulingIgnoredDuringExecution:
        nodeSelectorTerms:
        - matchExpressions:
          - key: gke.google.com/recommended-to-run-large-training-workload
            operator: NotIn
            values:
            - "False"
...
```

### Verify node labeling

After the CronJob runs for the first time, which is approximately 10 minutes
after deployment, verify whether it has applied the
`gke.google.com/recommended-to-run-large-training-workload` label to your nodes.

View a list of nodes that have the
`gke.google.com/recommended-to-run-large-training-workload` label applied to
them:

```bash
kubectl get nodes -L gke.google.com/recommended-to-run-large-training-workload
```

The label value can be one of the following:

- **`true`**: the node is predicted to be healthy in the next five hours.

- **`false`**: the node is likely to degrade within the next five hours. If
  you configured your Job configuration as described in this document, then
  Kueue avoids scheduling new workloads on the node.

## What's next

- To learn about managing common events relevant to GKE
  clusters and AI workloads, see
  [Manage AI-optimized GKE clusters](https://docs.cloud.google.com/ai-hypercomputer/docs/manage/manage-gke-clusters.md.txt).

- To learn more about scheduling jobs on GKE with Kueue, see
  [Deploy a batch system using Kueue](https://docs.cloud.google.com/kubernetes-engine/docs/tutorials/kueue-intro.md.txt).