-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate-dns.sh
executable file
·54 lines (42 loc) · 1.32 KB
/
update-dns.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
#!/usr/bin/env bash
set -e
set -x
# Run before to configure kubectl to access the GKE cluster:
# gcloud container clusters get-credentials gke-cluster --region europe-west1-b --project moderate-prod
: ${BASE_DOMAIN:="moderate.cloud"}
: ${NGINX_CONTROLLER_SERVICE:="ingress-nginx-controller"}
: ${PROJECT_ID:="moderate-common"}
: ${MANAGED_ZONE:="moderate-cloud"}
: ${TTL:="300"}
DOMAINS=(
'*'
'docs'
)
LB_IP=$(kubectl get \
service/${NGINX_CONTROLLER_SERVICE} \
-o jsonpath='{.status.loadBalancer.ingress[0].ip}')
gcloud --project=${PROJECT_ID} \
dns record-sets transaction abort \
--zone=${MANAGED_ZONE} || true
gcloud --project=${PROJECT_ID} \
dns record-sets transaction start \
--zone=${MANAGED_ZONE}
for val in "${DOMAINS[@]}"; do
CURR_DOMAIN="${val}.${BASE_DOMAIN}"
gcloud --project=${PROJECT_ID} \
dns record-sets delete ${CURR_DOMAIN} \
--type=A \
--zone=${MANAGED_ZONE} || true
gcloud --project=${PROJECT_ID} \
dns record-sets transaction add ${LB_IP} \
--name=${CURR_DOMAIN} \
--ttl=${TTL} \
--type=A \
--zone=${MANAGED_ZONE}
done
gcloud --project=${PROJECT_ID} \
dns record-sets transaction execute \
--zone=${MANAGED_ZONE}
gcloud --project=${PROJECT_ID} \
dns record-sets list \
--zone=${MANAGED_ZONE}