-
Notifications
You must be signed in to change notification settings - Fork 1
/
launch_cluster.py
153 lines (128 loc) · 3.59 KB
/
launch_cluster.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
import argparse
import random
import subprocess
from typing import List
from constants import *
VALID_ACCELERATORS = [
"nvidia-a100-80gb",
"nvidia-tesla-a100",
"nvidia-l4",
"nvidia-tesla-t4",
"nvidia-tesla-p4",
"nvidia-tesla-v100",
"nvidia-tesla-p100",
"nvidia-tesla-k80",
]
def _run_command(cmd: List[str]):
try:
cp = subprocess.run(cmd, check=True, capture_output=True)
except subprocess.CalledProcessError as e:
print(f"Error: {e.output}")
raise e
split_out = cp.stdout.decode().split("\n")
split_err = cp.stderr.decode().split("\n")
for line in split_out:
print(line)
for line in split_err:
print(line)
def _launch_cluster(cluster_name: str, machine_type: str, a_type: str, sub: str):
cli_args = [
"gcloud",
"beta",
"container",
"--project",
PROJECT,
"clusters",
"create",
cluster_name,
"--no-enable-basic-auth",
"--cluster-version",
"1.27.3-gke.100",
"--release-channel",
"None",
"--machine-type",
machine_type,
"--accelerator",
f"type={a_type},count=1",
"--image-type",
"COS_CONTAINERD",
"--disk-type",
"pd-balanced",
"--disk-size",
"100",
"--metadata",
"disable-legacy-endpoints=true",
"--scopes",
SCOPES,
"--num-nodes",
"1",
"--logging=SYSTEM,WORKLOAD",
"--monitoring=SYSTEM",
"--enable-private-nodes",
"--master-ipv4-cidr",
f"172.{sub}.0.0/28",
"--enable-ip-alias",
"--network",
NETWORK,
"--subnetwork",
SUBNETWORK,
"--no-enable-intra-node-visibility",
"--default-max-pods-per-node",
"110",
"--security-posture=standard",
"--workload-vulnerability-scanning=disabled",
"--no-enable-master-authorized-networks",
"--addons",
"HorizontalPodAutoscaling,HttpLoadBalancing,GcePersistentDiskCsiDriver",
"--enable-autoupgrade",
"--enable-autorepair",
"--max-surge-upgrade",
"1",
"--max-unavailable-upgrade",
"0",
"--binauthz-evaluation-mode=DISABLED",
"--enable-managed-prometheus",
"--enable-shielded-nodes",
"--node-locations",
REGION,
"--zone",
ZONE,
]
print(
f"Attempting to launch {cluster_name} - this can take five minutes or more..."
)
_run_command(cli_args)
def _parse_args() -> argparse.Namespace:
parser = argparse.ArgumentParser()
parser.add_argument(
"--accelerator_type",
type=str,
required=True,
help=f"Choose from {VALID_ACCELERATORS}",
)
return parser.parse_args()
def main():
args = _parse_args()
a_type = args.accelerator_type
cluster_name = f"gke-gpu-{a_type}-1-cluster"
sub = random.randint(0, 63) * 4
machine_type: str
if a_type == "nvidia-l4":
machine_type = "g2-standard-12"
if a_type == "nvidia-a100-80gb":
machine_type = "a2-ultragpu-1g"
if a_type == "nvidia-tesla-a100":
machine_type = "a2-highgpu-1g"
if a_type in [
"nvidia-tesla-t4",
"nvidia-tesla-v100",
"nvidia-tesla-p4",
"nvidia-tesla-p100",
"nvidia-tesla-k80",
]:
machine_type = "n1-highmem-8"
if a_type not in VALID_ACCELERATORS:
raise Exception(f"{a_type} is not a valid accelerator type")
_launch_cluster(cluster_name, machine_type, a_type, sub)
if __name__ == "__main__":
main()