dyn.md 4.24 KB
Newer Older
Julian Vassev's avatar
Julian Vassev committed
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
# Setting up ExternalDNS for Dyn

## Creating a Dyn Configuration Secret

For ExternalDNS to access the Dyn API, create a Kubernetes secret.

To create the secret:

```
$ kubectl create secret generic external-dns \
      --from-literal=EXTERNAL_DNS_DYN_CUSTOMER_NAME=${DYN_CUSTOMER_NAME} \
      --from-literal=EXTERNAL_DNS_DYN_USERNAME=${DYN_USERNAME} \
      --from-literal=EXTERNAL_DNS_DYN_PASSWORD=${DYN_PASSWORD}
```

The credentials are the same ones created during account registration. As best practise, you are advised to
create an API-only user that is entitled to only the zones intended to be changed by ExternalDNS

## Deploy ExternalDNS
The rest of this tutorial assumes you own `example.com` domain and your DNS provider is Dyn. Change `example.com`
with a domain/zone that you really own.

In case of the dyn provider, the flag `--zone-id-filter` is mandatory as it specifies which zones to scan for records. Without it


Create a deployment file called `externaldns.yaml` with the following contents:

28
29
```yaml
apiVersion: apps/v1
Julian Vassev's avatar
Julian Vassev committed
30
31
32
33
34
35
kind: Deployment
metadata:
  name: external-dns
spec:
  strategy:
    type: Recreate
36
37
38
  selector:
    matchLabels:
      app: external-dns
Julian Vassev's avatar
Julian Vassev committed
39
40
41
42
43
44
45
  template:
    metadata:
      labels:
        app: external-dns
    spec:
      containers:
      - name: external-dns
46
        image: k8s.gcr.io/external-dns/external-dns:v0.7.6
Julian Vassev's avatar
Julian Vassev committed
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
        args:
        - --source=ingress
        - --txt-prefix=_d
        - --namespace=example
        - --zone-id-filter=example.com
        - --domain-filter=example.com
        - --provider=dyn
        env:
        - name: EXTERNAL_DNS_DYN_CUSTOMER_NAME
          valueFrom:
            secretKeyRef:
              name: external-dns
              key: EXTERNAL_DNS_DYN_CUSTOMER_NAME
        - name: EXTERNAL_DNS_DYN_USERNAME
          valueFrom:
            secretKeyRef:
              name: external-dns
              key: EXTERNAL_DNS_DYN_USERNAME
        - name: EXTERNAL_DNS_DYN_PASSWORD
          valueFrom:
            secretKeyRef:
              name: external-dns
              key: EXTERNAL_DNS_DYN_PASSWORD
EOF
```

As we'll be creating an Ingress resource, you need `--txt-prefix=_d` as a CNAME cannot coexist with a TXT record. You can change the prefix to
any valid start of a FQDN.

Create the deployment for ExternalDNS:

```
$ kubectl create -f externaldns.yaml
```

## Running a locally build version
If you just want to test ExternalDNS in dry-run mode locally without doing the above deployment you can also do it.
Make sure your kubectl is configured correctly . Assuming you have the sources, build and run it like so:

```bash
make 
# output skipped

./build/external-dns \
    --provider=dyn \
    --dyn-customer-name=${DYN_CUSTOMER_NAME} \
    --dyn-username=${DYN_USERNAME} \
    --dyn-password=${DYN_PASSWORD} \
    --domain-filter=example.com \
    --zone-id-filter=example.com \
    --namespace=example \
    --log-level=debug \
    --txt-prefix=_ \
    --dry-run=true
INFO[0000] running in dry-run mode. No changes to DNS records will be made. 
INFO[0000] Connected to cluster at https://some-k8s-cluster.example.com 
INFO[0001] Zones: [example.com]
# output skipped
```

Having `--dry-run=true` and `--log-level=debug` is a great way to see _exactly_ what DynamicDNS is doing or is about to do.

## Deploying an Ingress Resource

Create a file called 'test-ingress.yaml' with the following contents:

```yaml
Kundan Kumar's avatar
Kundan Kumar committed
114
apiVersion: networking.k8s.io/v1
Julian Vassev's avatar
Julian Vassev committed
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
kind: Ingress
metadata:  
  name: test-ingress
  namespace: example
spec:
  rules:
  - host: test-ingress.example.com
    http:
      paths:
      - backend:
          serviceName: my-awesome-service
          servicePort: 8080

```

As the DNS name `test-ingress.example.com` matches the filter, external-dns will create two records:
a CNAME for test-ingress.example.com and TXT for _dtest-ingress.example.com. 

David Dymko's avatar
David Dymko committed
133
Create the Ingress:
Julian Vassev's avatar
Julian Vassev committed
134
135
136
137
138
139
140
141
142
143
144
145
146

```
$ kubectl create -f test-ingress.yaml
```

By default external-dns scans for changes every minute so give it some time to catch up with the 
## Verifying Dyn DNS records

Login to the console at https://portal.dynect.net/login/ and verify records are created

## Clean up

Login to the console at https://portal.dynect.net/login/ and delete the records created. Alternatively, just delete the sample
Nick Jüttner's avatar
Nick Jüttner committed
147
Ingress resources and external-dns will delete the records.