linode.md 4.84 KB
Newer Older
cliedeman's avatar
cliedeman committed
1
2
3
4
# Setting up ExternalDNS for Services on Linode

This tutorial describes how to setup ExternalDNS for usage within a Kubernetes cluster using Linode DNS Manager.

5
Make sure to use **>=0.5.5** version of ExternalDNS for this tutorial.
cliedeman's avatar
cliedeman committed
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26

## Managing DNS with Linode

If you want to learn about how to use Linode DNS Manager read the following tutorials:

[An Introduction to Managing DNS](https://www.linode.com/docs/platform/manager/dns-manager/), and [general documentation](https://www.linode.com/docs/networking/dns/)

## Creating Linode Credentials

Generate a new oauth token by following the instructions at [Access-and-Authentication](https://developers.linode.com/api/v4#section/Access-and-Authentication)

The environment variable `LINODE_TOKEN` will be needed to run ExternalDNS with Linode.

## Deploy ExternalDNS

Connect your `kubectl` client to the cluster you want to test ExternalDNS with.
Then apply one of the following manifests file to deploy ExternalDNS.

### Manifest (for clusters without RBAC enabled)

```yaml
27
apiVersion: apps/v1
cliedeman's avatar
cliedeman committed
28
29
30
31
32
33
kind: Deployment
metadata:
  name: external-dns
spec:
  strategy:
    type: Recreate
34
35
36
  selector:
    matchLabels:
      app: external-dns
cliedeman's avatar
cliedeman committed
37
38
39
40
41
42
43
  template:
    metadata:
      labels:
        app: external-dns
    spec:
      containers:
      - name: external-dns
44
        image: k8s.gcr.io/external-dns/external-dns:v0.7.3
cliedeman's avatar
cliedeman committed
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
        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=linode
        env:
        - name: LINODE_TOKEN
          value: "YOUR_LINODE_API_KEY"
```

### Manifest (for clusters with RBAC enabled)

```yaml
apiVersion: v1
kind: ServiceAccount
metadata:
  name: external-dns
---
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRole
metadata:
  name: external-dns
rules:
- apiGroups: [""]
Alfred Krohmer's avatar
Alfred Krohmer committed
68
  resources: ["services","endpoints","pods"]
cliedeman's avatar
cliedeman committed
69
  verbs: ["get","watch","list"]
70
- apiGroups: ["extensions","networking.k8s.io"]
cliedeman's avatar
cliedeman committed
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
  resources: ["ingresses"]
  verbs: ["get","watch","list"]
- apiGroups: [""]
  resources: ["nodes"]
  verbs: ["list"]
---
apiVersion: rbac.authorization.k8s.io/v1beta1
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
---
90
apiVersion: apps/v1
cliedeman's avatar
cliedeman committed
91
92
93
94
95
96
kind: Deployment
metadata:
  name: external-dns
spec:
  strategy:
    type: Recreate
97
98
99
  selector:
    matchLabels:
      app: external-dns
cliedeman's avatar
cliedeman committed
100
101
102
103
104
105
106
107
  template:
    metadata:
      labels:
        app: external-dns
    spec:
      serviceAccountName: external-dns
      containers:
      - name: external-dns
108
        image: k8s.gcr.io/external-dns/external-dns:v0.7.3
cliedeman's avatar
cliedeman committed
109
110
111
112
113
114
115
116
117
118
119
120
121
122
        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=linode
        env:
        - name: LINODE_TOKEN
          value: "YOUR_LINODE_API_KEY"
```

## Deploying an Nginx Service

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

```yaml
123
apiVersion: apps/v1
cliedeman's avatar
cliedeman committed
124
125
126
127
kind: Deployment
metadata:
  name: nginx
spec:
128
129
130
  selector:
    matchLabels:
      app: nginx
cliedeman's avatar
cliedeman committed
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
  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: my-app.example.com
spec:
  selector:
    app: nginx
  type: LoadBalancer
  ports:
    - protocol: TCP
      port: 80
      targetPort: 80
```

Note the annotation on the service; use the same hostname as the Linode DNS zone created above.

ExternalDNS uses this annotation to determine what services should be registered with DNS. Removing the annotation will cause ExternalDNS to remove the corresponding DNS records.

Create the deployment and service:

```console
$ kubectl create -f nginx.yaml
```

Depending where you run your service it can take a little while for your cloud provider to create an external IP for the service.

Once the service has an external IP assigned, ExternalDNS will notice the new service IP address and synchronize the Linode DNS records.

## Verifying Linode DNS records

174
Check your [Linode UI](https://cloud.linode.com/domains) to view the records for your Linode DNS zone.
cliedeman's avatar
cliedeman committed
175
176
177
178
179
180
181
182
183
184
185
186
187

Click on the zone for the one created above if a different domain was used.

This should show the external IP address of the service as the A record for your domain.

## Cleanup

Now that we have verified that ExternalDNS will automatically manage Linode DNS records, we can delete the tutorial's example:

```
$ kubectl delete service -f nginx.yaml
$ kubectl delete service -f externaldns.yaml
```