-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path4b_load_balance_collector.sh
executable file
·92 lines (62 loc) · 2.87 KB
/
4b_load_balance_collector.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
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
#!/bin/bash
. ./0_set_environment.sh
. ./0_functions.sh
if [ ! -z "${GSP_PROJECT_NAME}x" ] ; then
echo "Creating load balancing and DNS"
else
echo "GSP_ env not found. Set first"
exit 1
fi
# load balancing requires..
echo ....... health check
gcloud compute --project ${GSP_PROJECT_NAME} health-checks create http ${GSP_COLLECTOR_HEALTH} \
--check-interval=300s --port=${GSP_COLLECTOR_PORT} \
--request-path=/health --unhealthy-threshold=3
echo ....... create backend-service
gcloud compute --project ${GSP_PROJECT_NAME} \
instance-groups set-named-ports ${GSP_COLLECTOR_INSTANCE_GROUP_NAME} \
--named-ports collector-port:${GSP_COLLECTOR_PORT} \
--zone ${GSP_REGION}
gcloud compute --project ${GSP_PROJECT_NAME} backend-services create ${GSP_COLLECTOR_INSTANCE_NAME}-backend-service \
--health-checks ${GSP_COLLECTOR_HEALTH} \
--protocol=HTTP \
--port-name collector-port \
--global
echo ....... adding backend-service to instance
gcloud compute --project ${GSP_PROJECT_NAME} \
backend-services add-backend ${GSP_COLLECTOR_INSTANCE_NAME}-backend-service \
--instance-group ${GSP_COLLECTOR_INSTANCE_GROUP_NAME} \
--instance-group-zone ${GSP_REGION}
echo ....... url map
gcloud compute --project ${GSP_PROJECT_NAME} \
url-maps create ${GSP_COLLECTOR_INSTANCE_NAME}-url-map \
--default-service ${GSP_COLLECTOR_INSTANCE_NAME}-backend-service \
gcloud compute --project ${GSP_PROJECT_NAME} \
url-maps add-path-matcher ${GSP_COLLECTOR_INSTANCE_NAME}-url-map \
--path-matcher-name=${GSP_COLLECTOR_INSTANCE_NAME}-path-matcher \
--new-hosts ${GSP_TRACKER_HOST} \
--default-service ${GSP_COLLECTOR_INSTANCE_NAME}-backend-service
echo "....... ssl cert (managed by google)"
gcloud beta compute --project ${GSP_PROJECT_NAME} \
ssl-certificates create ${GSP_COLLECTOR_INSTANCE_NAME}-certificate \
--domains ${GSP_TRACKER_HOST}
echo ....... ssl-proxy
gcloud compute --project ${GSP_PROJECT_NAME} \
target-https-proxies create ${GSP_COLLECTOR_INSTANCE_NAME}-https-proxy \
--url-map=${GSP_COLLECTOR_INSTANCE_NAME}-url-map \
--ssl-certificates ${GSP_COLLECTOR_INSTANCE_NAME}-certificate
echo ....... IP address..
# get (or create) ip (from 0_functions.sh file ) - or create one
export MY_IP=$(create_ip)
echo ....... forwarding rule
gcloud compute --project ${GSP_PROJECT_NAME} \
forwarding-rules create ${GSP_COLLECTOR_INSTANCE_NAME}-forwarding-rule \
--address ${MY_IP} \
--global --ip-protocol TCP --ports=443 \
--target-https-proxy=${GSP_COLLECTOR_INSTANCE_NAME}-https-proxy
echo ....... DNS - not executing.. do it yourself (or paste, if domain is goole hosted)
echo set A record for ${GSP_TRACKER_HOST}. with IP ${MY_IP}
echo gcloud dns record-sets transaction start --zone=ZONENAME
echo gcloud dns record-sets transaction add ${MY_IP} --name=${GSP_TRACKER_HOST}. --ttl=300 --type=A --zone=ZONENAME
echo gcloud dns record-sets transaction execute --zone=ZONENAME
echo "Done"