-
Notifications
You must be signed in to change notification settings - Fork 6
/
calatrava-configure-dns.sh
executable file
·69 lines (51 loc) · 1.73 KB
/
calatrava-configure-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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/env bash
source "$(dirname $0)/functions.sh"
set -e
function enableExternalDns {
banner "Enabling External DNS"
kubectl apply -f \
https://raw.githubusercontent.com/kubernetes-sigs/external-dns/v0.7.1/docs/contributing/crd-source/crd-manifest.yaml
}
function createDnsRecord {
local fqdn="$1"
local service="$2"
local namespace="$3"
banner "Creating DNS record for $fqdn"
local ip=$(kubectl get -n $namespace service $service -o jsonpath='{$.status.loadBalancer.ingress[0].ip}')
if [[ "$ip" == "" ]]
then
message "Can't find IP address for service '$service' in namespace '$namespace'"
return
fi
kubectl apply -f- <<EOF
apiVersion: externaldns.k8s.io/v1alpha1
kind: DNSEndpoint
metadata:
name: $service-$namespace
spec:
endpoints:
- dnsName: $fqdn
recordTTL: 180
recordType: A
targets:
- $ip
EOF
}
cat << EOF
This script sets up DNS for TAP installations within the calatrava.vmware.com domain.
DNS for the main system ingress (via Contour/Envoy) should have been taken
care of via annotations added during that package installation. This script
only deals with the remaining DNS entries not handled in that manner.
Note that you DO NOT need to run this script if you are exposing the TAP
GUI via the system ingress as tap-gui.<namespace>.calatrava.vmware.com,
which is the default behaviour of the setup.sh script.
EOF
findOrPrompt DOMAIN "Root Domain"
findOrPromptWithDefault GUI_DOMAIN "UI Domain" "gui.${DOMAIN}"
if [[ "$DOMAIN" != *.calatrava.vmware.com ]] || [[ "$GUI_DOMAIN" != *.calatrava.vmware.com ]]
then
message "This script can only be used to set up DNS within the calatrava.vmware.com domain"
exit 1
fi
enableExternalDns
createDnsRecord "$GUI_DOMAIN" server tap-gui