|
| 1 | +# Setting up ExternalDNS for Services on OpenStack Designate |
| 2 | + |
| 3 | +This tutorial describes how to setup ExternalDNS for usage within a Kubernetes cluster using OpenStack Designate DNS. |
| 4 | + |
| 5 | +## Authenticating with OpenStack |
| 6 | + |
| 7 | +We are going to use OpenStack CLI - `openstack` utility, which is an umbrella application for most of OpenStack clients including `designate`. |
| 8 | + |
| 9 | +All OpenStack CLIs require authentication parameters to be provided. These parameters include: |
| 10 | +* URL of the OpenStack identity service (`keystone`) which is responsible for user authentication and also served as a registry for other |
| 11 | + OpenStack services. Designate endpoints must be registered in `keystone` in order to ExternalDNS and OpenStack CLI be able to find them. |
| 12 | +* OpenStack region name |
| 13 | +* User login name. |
| 14 | +* User project (tenant) name. |
| 15 | +* User domain (only when using keystone API v3) |
| 16 | + |
| 17 | +Although these parameters can be passed explicitly through the CLI flags, traditionally it is done by sourcing `openrc` file (`source ~/openrc`) that is a |
| 18 | +shell snippet that sets environment variables that all OpenStack CLI understand by convention. |
| 19 | + |
| 20 | +Recent versions of OpenStack Dashboard have a nice UI to download `openrc` file for both v2 and v3 auth protocols. Both protocols can be used with ExternalDNS. |
| 21 | +v3 is generally preferred over v2, but might not be available in some OpenStack installations. |
| 22 | + |
| 23 | +## Installing OpenStack Designate |
| 24 | + |
| 25 | +Please refer to the Designate deployment [tutorial](https://docs.openstack.org/project-install-guide/dns/ocata/install.html) for instructions on how |
| 26 | +to install and test Designate with BIND backend. You will be required to have admin rights in existing OpenStack installation to do this. One convenient |
| 27 | +way to get yourself an OpenStack installation to play with is to use [DevStack](https://docs.openstack.org/devstack/latest/). |
| 28 | + |
| 29 | +## Creating DNS zones |
| 30 | + |
| 31 | +All domain names that are ExternalDNS is going to create must belong to one of DNS zones created in advance. Here is an example of how to create `example.com` DNS zone: |
| 32 | +```console |
| 33 | +$ openstack zone create --email [email protected] example.com. |
| 34 | +``` |
| 35 | + |
| 36 | +It is important to manually create all the zones that are going to be used for kubernetes entities (ExternalDNS sources) before starting ExternalDNS. |
| 37 | + |
| 38 | +## Deploy ExternalDNS |
| 39 | + |
| 40 | +Create a deployment file called `externaldns.yaml` with the following contents: |
| 41 | + |
| 42 | +```yaml |
| 43 | +apiVersion: extensions/v1beta1 |
| 44 | +kind: Deployment |
| 45 | +metadata: |
| 46 | + name: external-dns |
| 47 | +spec: |
| 48 | + strategy: |
| 49 | + type: Recreate |
| 50 | + template: |
| 51 | + metadata: |
| 52 | + labels: |
| 53 | + app: external-dns |
| 54 | + spec: |
| 55 | + containers: |
| 56 | + - name: external-dns |
| 57 | + image: registry.opensource.zalan.do/teapot/external-dns |
| 58 | + args: |
| 59 | + - --source=service # ingress is also possible |
| 60 | + - --domain-filter=example.com # (optional) limit to only example.com domains; change to match the zone created above. |
| 61 | + - --provider=designate |
| 62 | + env: # values from openrc file |
| 63 | + - name: OS_AUTH_URL |
| 64 | + value: http://controller/identity/v3 |
| 65 | + - name: OS_REGION_NAME |
| 66 | + value: RegionOne |
| 67 | + - name: OS_USERNAME |
| 68 | + value: admin |
| 69 | + - name: OS_PASSWORD |
| 70 | + value: p@ssw0rd |
| 71 | + - name: OS_PROJECT_NAME |
| 72 | + value: demo |
| 73 | + - name: OS_USER_DOMAIN_NAME |
| 74 | + value: Default |
| 75 | +``` |
| 76 | +
|
| 77 | +Create the deployment for ExternalDNS: |
| 78 | +
|
| 79 | +```console |
| 80 | +$ kubectl create -f externaldns.yaml |
| 81 | +``` |
| 82 | + |
| 83 | +## Deploying an Nginx Service |
| 84 | + |
| 85 | +Create a service file called 'nginx.yaml' with the following contents: |
| 86 | + |
| 87 | +```yaml |
| 88 | +apiVersion: extensions/v1beta1 |
| 89 | +kind: Deployment |
| 90 | +metadata: |
| 91 | + name: nginx |
| 92 | +spec: |
| 93 | + template: |
| 94 | + metadata: |
| 95 | + labels: |
| 96 | + app: nginx |
| 97 | + spec: |
| 98 | + containers: |
| 99 | + - image: nginx |
| 100 | + name: nginx |
| 101 | + ports: |
| 102 | + - containerPort: 80 |
| 103 | +--- |
| 104 | +apiVersion: v1 |
| 105 | +kind: Service |
| 106 | +metadata: |
| 107 | + name: nginx |
| 108 | + annotations: |
| 109 | + external-dns.alpha.kubernetes.io/hostname: my-app.example.com |
| 110 | +spec: |
| 111 | + selector: |
| 112 | + app: nginx |
| 113 | + type: LoadBalancer |
| 114 | + ports: |
| 115 | + - protocol: TCP |
| 116 | + port: 80 |
| 117 | + targetPort: 80 |
| 118 | +``` |
| 119 | +
|
| 120 | +Note the annotation on the service; use the same hostname as the DNS zone created above. |
| 121 | +
|
| 122 | +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. |
| 123 | +
|
| 124 | +Create the deployment and service: |
| 125 | +
|
| 126 | +```console |
| 127 | +$ kubectl create -f nginx.yaml |
| 128 | +``` |
| 129 | + |
| 130 | + |
| 131 | +Once the service has an external IP assigned, ExternalDNS will notice the new service IP address and notify Designate, |
| 132 | +which in turn synchronize DNS records with underlying DNS server backend. |
| 133 | + |
| 134 | +## Verifying DNS records |
| 135 | + |
| 136 | +To verify that DNS record was indeed created, you can use the following command: |
| 137 | + |
| 138 | +```console |
| 139 | +$ openstack recordset list example.com. |
| 140 | +``` |
| 141 | + |
| 142 | +There should be a record for my-app.example.com having `ACTIVE` status. And of course, the ultimate method to verify is to issue a DNS query: |
| 143 | + |
| 144 | +```console |
| 145 | +$ dig my-app.example.com @controller |
| 146 | +``` |
| 147 | + |
| 148 | +## Cleanup |
| 149 | + |
| 150 | +Now that we have verified that ExternalDNS created all DNS records, we can delete the tutorial's example: |
| 151 | + |
| 152 | +```console |
| 153 | +$ kubectl delete service -f nginx.yaml |
| 154 | +$ kubectl delete service -f externaldns.yaml |
| 155 | +``` |
0 commit comments