rcodezero.md 6.68 KB
Newer Older
1
2
# Setting up ExternalDNS for Services on RcodeZero

Dimitrij Klesev's avatar
Dimitrij Klesev committed
3
This tutorial describes how to setup ExternalDNS for usage within a Kubernetes cluster using [RcodeZero Anycast DNS](https://www.rcodezero.at). Make sure to use **>=0.5.0** version of ExternalDNS for this tutorial.
4

Dimitrij Klesev's avatar
Dimitrij Klesev committed
5
6
7
8
9
10
11
The following steps are required to use RcodeZero with ExternalDNS:

1. Sign up for an RcodeZero account (or use an existing account).
2. Add your zone to the RcodeZero DNS
3. Enable the RcodeZero API, and generate an API key.
4. Deploy ExternalDNS to use the RcodeZero provider.
5. Verify the setup bey deploying a test services (optional)
12
13
14

## Creating a RcodeZero DNS zone

Dimitrij Klesev's avatar
Dimitrij Klesev committed
15
Before records can be added to your domain name automatically, you need to add your domain name to the set of zones managed by RcodeZero. In order to add the zone, perform the following steps:
16

Dimitrij Klesev's avatar
Dimitrij Klesev committed
17
18
1. Log in to the RcodeZero Dashboard, and move to the [Add Zone](https://my.rcodezero.at/domain/create) page.
2. Select "MASTER" as domain type, and add your domain name there. Use this domain name instead of "example.com" throughout the rest of this tutorial. 
19

Dimitrij Klesev's avatar
Dimitrij Klesev committed
20
21
22
Note that "SECONDARY" domains cannot be managed by ExternalDNS, because this would not allow modification of records in the zone.

## Enable the API, and create Credentials
23

Dimitrij Klesev's avatar
Dimitrij Klesev committed
24
> The RcodeZero Anycast-Network is provisioned via web interface or REST-API.
25

Dimitrij Klesev's avatar
Dimitrij Klesev committed
26
Enable the RcodeZero API to generate an API key on [RcodeZero API](https://my.rcodezero.at/enableapi). The API key will be added to the environment variable 'RC0_API_KEY' via one of the Manifest templates (as described below).
27
28
29

## Deploy ExternalDNS

Dimitrij Klesev's avatar
Dimitrij Klesev committed
30
31
32
33
34
Connect your `kubectl` client to the cluster you want to test ExternalDNS with. Choose a Manifest from below, depending on whether or not you have RBAC enabled. Before applying it, modify the Manifest as follows:

- Replace "example.com" with the domain name you added to RcodeZero.
- Replace YOUR_RCODEZERO_API_KEY with the API key created above.
- Replace YOUR_ENCRYPTION_KEY_STRING with a string to encrypt the TXT records
35
36
37
38

### Manifest (for clusters without RBAC enabled)

```yaml
39
apiVersion: apps/v1
40
41
42
43
44
45
kind: Deployment
metadata:
  name: external-dns
spec:
  strategy:
    type: Recreate
46
47
48
  selector:
    matchLabels:
      app: external-dns
49
50
51
52
53
54
55
  template:
    metadata:
      labels:
        app: external-dns
    spec:
      containers:
      - name: external-dns
56
        image: k8s.gcr.io/external-dns/external-dns:v0.7.6
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
        args:
        - --source=service # ingress is also possible
        - --domain-filter=example.com # (optional) limit to only example.com domains; change to match the zone created above.
        - --provider=rcodezero
        - --rc0-enc-txt # (optional) encrypt TXT records; encryption key has to be provided with RC0_ENC_KEY env var.
        env:
        - name: RC0_API_KEY
          value: "YOUR_RCODEZERO_API_KEY"
        - name: RC0_ENC_VAR
          value: "YOUR_ENCRYPTION_KEY_STRING"
```

### Manifest (for clusters with RBAC enabled)

```yaml
apiVersion: v1
kind: ServiceAccount
metadata:
  name: external-dns
---
Kundan Kumar's avatar
Kundan Kumar committed
77
apiVersion: rbac.authorization.k8s.io/v1
78
79
80
81
82
kind: ClusterRole
metadata:
  name: external-dns
rules:
- apiGroups: [""]
Alfred Krohmer's avatar
Alfred Krohmer committed
83
  resources: ["services","endpoints","pods"]
84
  verbs: ["get","watch","list"]
85
- apiGroups: ["extensions","networking.k8s.io"]
86
87
88
89
90
91
  resources: ["ingresses"] 
  verbs: ["get","watch","list"]
- apiGroups: [""]
  resources: ["nodes"]
  verbs: ["list"]
---
Kundan Kumar's avatar
Kundan Kumar committed
92
apiVersion: rbac.authorization.k8s.io/v1
93
94
95
96
97
98
99
100
101
102
103
104
kind: ClusterRoleBinding
metadata:
  name: external-dns-viewer
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: external-dns
subjects:
- kind: ServiceAccount
  name: external-dns
  namespace: default
---
105
apiVersion: apps/v1
106
107
108
109
110
111
kind: Deployment
metadata:
  name: external-dns
spec:
  strategy:
    type: Recreate
112
113
114
  selector:
    matchLabels:
      app: external-dns
115
116
117
118
119
120
121
122
  template:
    metadata:
      labels:
        app: external-dns
    spec:
      serviceAccountName: external-dns
      containers:
      - name: external-dns
123
        image: k8s.gcr.io/external-dns/external-dns:v0.7.6
124
125
126
127
128
129
130
131
132
133
134
135
136
137
        args:
        - --source=service # ingress is also possible
        - --domain-filter=example.com # (optional) limit to only example.com domains; change to match the zone created above.
        - --provider=rcodezero
        - --rc0-enc-txt # (optional) encrypt TXT records; encryption key has to be provided with RC0_ENC_KEY env var.
        env:
        - name: RC0_API_KEY
          value: "YOUR_RCODEZERO_API_KEY"
        - name: RC0_ENC_VAR
          value: "YOUR_ENCRYPTION_KEY_STRING"
```

## Deploying an Nginx Service

Dimitrij Klesev's avatar
Dimitrij Klesev committed
138
139
After you have deployed ExternalDNS with RcodeZero, you can deploy a simple service based on Nginx to test the setup. This is optional, though highly recommended before using ExternalDNS in production.

140
141
142
Create a service file called 'nginx.yaml' with the following contents:

```yaml
143
apiVersion: apps/v1
144
145
146
147
kind: Deployment
metadata:
  name: nginx
spec:
148
149
150
  selector:
    matchLabels:
      app: nginx
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - image: nginx
        name: nginx
        ports:
        - containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
  name: nginx
  annotations:
    external-dns.alpha.kubernetes.io/hostname: example.com
    external-dns.alpha.kubernetes.io/ttl: "120" #optional
spec:
  selector:
    app: nginx
  type: LoadBalancer
  ports:
    - protocol: TCP
      port: 80
      targetPort: 80
```

Dimitrij Klesev's avatar
Dimitrij Klesev committed
179
Change the file as follows:
180

Dimitrij Klesev's avatar
Dimitrij Klesev committed
181
182
183
- Replace the annotation of the service; use the same hostname as the RcodeZero DNS zone created above. The annotation may also be a subdomain
of the DNS zone (e.g. 'www.example.com').
- Set the TTL annotation of the service. A valid TTL of 120 or above must be given. This annotation is optional, and defaults to "300" if no value is given.
184

Dimitrij Klesev's avatar
Dimitrij Klesev committed
185
These annotations will be used to determine what services should be registered with DNS. Removing these annotations will cause ExternalDNS to remove the corresponding DNS records.
186

Dimitrij Klesev's avatar
Dimitrij Klesev committed
187
Create the Deployment and Service:
188

Dimitrij Klesev's avatar
Dimitrij Klesev committed
189
```bash
190
191
192
$ kubectl create -f nginx.yaml
```

Dimitrij Klesev's avatar
Dimitrij Klesev committed
193
Depending on your cloud provider, it might take a while to create an external IP for the service. Once an external IP address is assigned to the service, ExternalDNS will notice the new address and synchronize the RcodeZero DNS records accordingly.
194
195
196

## Verifying RcodeZero DNS records

Dimitrij Klesev's avatar
Dimitrij Klesev committed
197
Check your [RcodeZero Configured Zones](https://my.rcodezero.at/domain) and select the respective zone name. The zone should now contain the external IP address of the service as an A record.
198
199
200

## Cleanup

Dimitrij Klesev's avatar
Dimitrij Klesev committed
201
Once you have verified that ExternalDNS successfully manages RcodeZero DNS records for external services, you can delete the tutorial example as follows:
202

Dimitrij Klesev's avatar
Dimitrij Klesev committed
203
```bash
204
205
206
$ kubectl delete -f nginx.yaml
$ kubectl delete -f externaldns.yaml
```