|
| 1 | +## Create a TPU 7x Flex cluster |
| 2 | +These steps guide you through the cluster creation process for TPUs using DWS Flex Start. |
| 3 | + |
| 4 | +1. Complete the common setup steps (1-4) in the [Create a cluster](https://github.com/GoogleCloudPlatform/cluster-toolkit/tree/main/examples/gke-consumption-options/dws-flex-start#create-a-cluster) section. |
| 5 | + |
| 6 | +1. In the `examples/gke-consumption-options/dws-flex-start/gke-tpu-7x/gke-tpu-7x-deployment.yaml` file, fill in the following settings in the terraform_backend_defaults and vars sections to match the specific values for your deployment: |
| 7 | + |
| 8 | + `bucket`: the name of the Cloud Storage bucket you created in the previous step. |
| 9 | + `deployment_name`: the name of the deployment. |
| 10 | + `project_id`: your Google Cloud project ID. |
| 11 | + `region`: the compute region for the cluster. |
| 12 | + `zone`: the compute zone for the node pool of TPU 7x machines. |
| 13 | + **`enable_flex_start`**: set to `true` to enable DWS Flex Start. |
| 14 | + **`autoscaling_min_node_count`**: set to `0` (required for Flex Start). |
| 15 | + **`autoscaling_max_node_count`**: set to the required node count for your topology (e.g., `2` for a `2x2x2` topology). |
| 16 | + `authorized_cidr`: The IP address range that you want to allow to connect with the cluster. |
| 17 | + To modify advanced settings, edit `examples/gke-consumption-options/dws-flex-start/gke-tpu-7x/gke-tpu-7x.yaml`. |
| 18 | + |
| 19 | +1. Generate [Application Default Credentials (ADC)](https://cloud.google.com/docs/authentication/provide-credentials-adc#google-idp) to provide access to Terraform. |
| 20 | + |
| 21 | + ```sh |
| 22 | + gcloud auth application-default login |
| 23 | + ``` |
| 24 | + |
| 25 | +1. Deploy the blueprint to provision the GKE infrastructure using TPU 7x machine types: |
| 26 | + |
| 27 | + ```sh |
| 28 | + cd ~/cluster-toolkit |
| 29 | + ./gcluster deploy -d \ |
| 30 | + examples/gke-consumption-options/dws-flex-start/gke-tpu-7x/gke-tpu-7x-deployment.yaml \ |
| 31 | + examples/gke-consumption-options/dws-flex-start/gke-tpu-7x/gke-tpu-7x.yaml |
| 32 | + ``` |
| 33 | + |
| 34 | +1. When prompted, select (A)pply to deploy the blueprint. |
| 35 | + |
| 36 | +## Note |
| 37 | + |
| 38 | +* DWS Flex Start does not work with static nodes. So, static_node_count cannot be set. |
| 39 | +* To use DWS Flex Start, `auto_repair` should be set to `false`. |
| 40 | + |
| 41 | +## Running Workloads with DWS Flex Start |
| 42 | + |
| 43 | +The Cluster Toolkit automatically generates a pre-configured, DWS-compliant job file located in your deployment folder (e.g., `gke-tpu-7x-flex/primary/my-job-xxxx.yaml`). |
| 44 | + |
| 45 | +If you wish to create your own custom job, ensure it includes the following critical settings: |
| 46 | + |
| 47 | +### 1. Node Selectors & Tolerations |
| 48 | +The job must target the TPU 7x nodes and tolerate the standard TPU taint: |
| 49 | + |
| 50 | +```yaml |
| 51 | +nodeSelector: |
| 52 | + cloud.google.com/gke-tpu-accelerator: "tpu7x" |
| 53 | + cloud.google.com/gke-tpu-topology: "2x2x2" |
| 54 | +tolerations: |
| 55 | +- key: google.com/tpu |
| 56 | + operator: Equal |
| 57 | + value: "present" |
| 58 | + effect: NoSchedule |
| 59 | +``` |
| 60 | + |
| 61 | +### 2. Resource Requests |
| 62 | + |
| 63 | +Each pod in the job should request the full amount of TPU chips available on the node (typically 4 for `tpu7x-standard-4t`): |
| 64 | + |
| 65 | +```yaml |
| 66 | +resources: |
| 67 | + limits: |
| 68 | + google.com/tpu: 4 |
| 69 | + requests: |
| 70 | + google.com/tpu: 4 |
| 71 | +``` |
| 72 | + |
| 73 | +### 3. Parallelism |
| 74 | + |
| 75 | +The `parallelism` and `completions` count in your Kubernetes Job (or ReplicatedJob replicas in a JobSet) must exactly match the number of nodes in your TPU slice (e.g., `2` for a `2x2x2` topology). |
| 76 | + |
| 77 | +## Testing TPU Flex Start (Dynamic Scaling) |
| 78 | + |
| 79 | +When using the TPU Flex Start model, the cluster begins with **0 nodes** in the TPU node pool. You can verify the dynamic scaling by following these steps: |
| 80 | + |
| 81 | +1. **Monitor the cluster status:** |
| 82 | + Open two terminals. In the first, watch the pods: |
| 83 | + |
| 84 | + ```sh |
| 85 | + kubectl get pods -w |
| 86 | + ``` |
| 87 | + |
| 88 | + In the second, watch the nodes: |
| 89 | + |
| 90 | + ```sh |
| 91 | + kubectl get nodes -w |
| 92 | + ``` |
| 93 | + |
| 94 | +2. **Submit the TPU job:** |
| 95 | + Submit the generated job file: |
| 96 | + |
| 97 | + ```sh |
| 98 | + kubectl apply -f <deployment_folder>/primary/my-job-xxxx.yaml |
| 99 | + ``` |
| 100 | + |
| 101 | +3. **Observe Scale-Up:** |
| 102 | + * **Initial State:** Pods will show as `Pending`. |
| 103 | + |
| 104 | + ```text |
| 105 | + NAME READY STATUS RESTARTS AGE |
| 106 | + my-job-2932-0-q2ksv 0/2 Pending 0 10s |
| 107 | + ``` |
| 108 | + |
| 109 | + * **Autoscaling Triggered:** Check events to see the scale-up trigger: `kubectl get events`. You will see `TriggeredScaleUp`. |
| 110 | + |
| 111 | + * **Nodes Joining:** After a few minutes, nodes will appear and transition to `Ready`. |
| 112 | + |
| 113 | + ```text |
| 114 | + NAME STATUS ROLES AGE VERSION |
| 115 | + gke-tpu-7f1325ce-8hwg Ready <none> 10s v1.34.1-gke.3971000 |
| 116 | + ``` |
| 117 | + |
| 118 | + * **Running:** Once nodes are ready, pods will transition to `Running`. |
| 119 | + |
| 120 | +4. **Observe Scale-Down:** |
| 121 | + * **Completion:** Once the workload finishes, pods will move to `Completed`. |
| 122 | + |
| 123 | + ```text |
| 124 | + NAME READY STATUS RESTARTS AGE |
| 125 | + my-job-2932-0-q2ksv 0/2 Completed 0 5m |
| 126 | + ``` |
| 127 | + |
| 128 | + * **Automatic Removal:** After a short idle period (typically 1-10 minutes), the Cluster Autoscaler will delete the nodes. |
| 129 | + |
| 130 | + ```text |
| 131 | + gke-tpu-7f1325ce-8hwg NotReady,SchedulingDisabled <none> 6m v1.34.1-gke.3971000 |
| 132 | + ``` |
| 133 | + |
| 134 | + * **Final State:** The node pool will return to **0 nodes**. |
0 commit comments