transip.md 5.16 KB
Newer Older
Reinier Schoof's avatar
Reinier Schoof committed
1
2
3
4
# Setting up ExternalDNS for Services on TransIP

This tutorial describes how to setup ExternalDNS for usage within a Kubernetes cluster using TransIP.

5
Make sure to use **>=0.5.14** version of ExternalDNS for this tutorial, have at least 1 domain registered at TransIP and enabled the API.
Reinier Schoof's avatar
Reinier Schoof committed
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21

## Enable TransIP API and prepare your API key

To use the TransIP API you need an account at TransIP and enable API usage as described in the [knowledge base](https://www.transip.eu/knowledgebase/entry/77-want-use-the-transip-api/). With the private key generated by the API, we create a kubernetes secret:

```console
$ kubectl create secret generic transip-api-key --from-file=transip-api-key=/path/to/private.key
```

## Deploy ExternalDNS

Below are example manifests, for both cluster without or with RBAC enabled. Don't forget to replace `YOUR_TRANSIP_ACCOUNT_NAME` with your TransIP account name. In these examples, an example domain-filter is defined. Such a filter can be used to prevent ExternalDNS from touching any domain not listed in the filter. Refer to the docs for any other command-line parameters you might want to use.

### Manifest (for clusters without RBAC enabled)

```yaml
22
apiVersion: apps/v1
Reinier Schoof's avatar
Reinier Schoof committed
23
24
25
26
27
28
kind: Deployment
metadata:
  name: external-dns
spec:
  strategy:
    type: Recreate
29
30
31
  selector:
    matchLabels:
      app: external-dns
Reinier Schoof's avatar
Reinier Schoof committed
32
33
34
35
36
37
38
  template:
    metadata:
      labels:
        app: external-dns
    spec:
      containers:
      - name: external-dns
39
        image: k8s.gcr.io/external-dns/external-dns:v0.7.6
Reinier Schoof's avatar
Reinier Schoof committed
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
        args:
        - --source=service # ingress is also possible
        - --domain-filter=example.com # (optional) limit to only example.com domains
        - --provider=transip
        - --transip-account=YOUR_TRANSIP_ACCOUNT_NAME
        - --transip-keyfile=/transip/transip-api-key
        volumeMounts:
        - mountPath: /transip
          name: transip-api-key
          readOnly: true
      volumes:
      - name: transip-api-key
        secret:
          secretName: transip-api-key
```

### Manifest (for clusters with RBAC enabled)

```yaml
apiVersion: v1
kind: ServiceAccount
metadata:
  name: external-dns
---
Kundan Kumar's avatar
Kundan Kumar committed
64
apiVersion: rbac.authorization.k8s.io/v1
Reinier Schoof's avatar
Reinier Schoof committed
65
66
67
68
69
kind: ClusterRole
metadata:
  name: external-dns
rules:
- apiGroups: [""]
Alfred Krohmer's avatar
Alfred Krohmer committed
70
  resources: ["services","endpoints","pods"]
Reinier Schoof's avatar
Reinier Schoof committed
71
  verbs: ["get","watch","list"]
72
- apiGroups: ["extensions","networking.k8s.io"]
Reinier Schoof's avatar
Reinier Schoof committed
73
74
75
76
  resources: ["ingresses"]
  verbs: ["get","watch","list"]
- apiGroups: [""]
  resources: ["nodes"]
77
  verbs: ["watch", "list"]
Reinier Schoof's avatar
Reinier Schoof committed
78
---
Kundan Kumar's avatar
Kundan Kumar committed
79
apiVersion: rbac.authorization.k8s.io/v1
Reinier Schoof's avatar
Reinier Schoof committed
80
81
82
83
84
85
86
87
88
89
90
91
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
---
92
apiVersion: apps/v1
Reinier Schoof's avatar
Reinier Schoof committed
93
94
95
96
97
98
kind: Deployment
metadata:
  name: external-dns
spec:
  strategy:
    type: Recreate
99
100
101
  selector:
    matchLabels:
      app: external-dns
Reinier Schoof's avatar
Reinier Schoof committed
102
103
104
105
106
107
108
109
  template:
    metadata:
      labels:
        app: external-dns
    spec:
      serviceAccountName: external-dns
      containers:
      - name: external-dns
110
        image: k8s.gcr.io/external-dns/external-dns:v0.7.6
Reinier Schoof's avatar
Reinier Schoof committed
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
        args:
        - --source=service # ingress is also possible
        - --domain-filter=example.com # (optional) limit to only example.com domains
        - --provider=transip
        - --transip-account=YOUR_TRANSIP_ACCOUNT_NAME
        - --transip-keyfile=/transip/transip-api-key
        volumeMounts:
        - mountPath: /transip
          name: transip-api-key
          readOnly: true
      volumes:
      - name: transip-api-key
        secret:
          secretName: transip-api-key
```

## Deploying an Nginx Service

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

```yaml
132
apiVersion: apps/v1
Reinier Schoof's avatar
Reinier Schoof committed
133
134
135
136
kind: Deployment
metadata:
  name: nginx
spec:
137
138
139
  selector:
    matchLabels:
      app: nginx
Reinier Schoof's avatar
Reinier Schoof committed
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
  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; this is the name ExternalDNS will create and manage DNS records for.

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 TransIP DNS records.

## Verifying TransIP DNS records

Check your [TransIP Control Panel](https://transip.eu/cp) to view the records for your TransIP DNS zone.

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.