-
Notifications
You must be signed in to change notification settings - Fork 0
/
instances_gcp.sh
executable file
·65 lines (41 loc) · 1.34 KB
/
instances_gcp.sh
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
#!/bin/bash
#GCP variables
export project=""
export zone=""
export machine=""
export subnet=""
export image=""
export instances=2 #Number of instances
function getGCPCompute {
list=$(gcloud beta compute --project=$project instances list --format=json | egrep '"name": "cka-node-.*"' | wc -l)
if [ $list -gt 0 ]; then
n=$(gcloud beta compute --project=$project instances list --format=json | egrep '"name": "cka-node-.*"' | wc -l)
else
n=0
fi
return $n
}
if getGCPCompute;[ $instances -gt $n ]; then
echo "Creating $(($instances -$n)) instance[s]"
for i in `seq $((instances-n))`;do
gcloud beta compute \
--project=cka-cloud-native \
instances create cka-node-$RANDOM \
--zone=$zone \
--machine-type=$machine\
--subnet=$subnet \
--network-tier=STANDARD \
--maintenance-policy=MIGRATE \
--image=$image \
--image-project=ubuntu-os-cloud \
--boot-disk-size=10GB \
--boot-disk-type=pd-balanced \
--boot-disk-device-name=cka-cluster \
--no-shielded-secure-boot \
--shielded-vtpm \
--shielded-integrity-monitoring \
--reservation-affinity=any
done
else
echo "Machines already created on Google Cloud"
fi