Google Kubernetes Engine with external-dns on CloudFlare provider

Marek Bartík
1 min readFeb 26, 2018

--

Having a bunch of kubernetes services and ingresses you will need some automation with creating DNS records. Let’s say you use CloudFlare as a DNS provider and your dev flow is to push in git repo, automagically deploy to GKE your app which is later exposed via kubernetes ingress externally. Your Ops takes the new ingress IP and creates a dns A record branch-name.yourdomain.tld

It is not hard to automate this with CloudFlare API and checking the existing services/ingresses with cron with somehow finding out what the DNS will look like.

Using external-dns, however, I have all of this out-of-the-box thanks to zalan.do running as a pod in GKE.

With ingress like this:

mind the metadata.annotations.external-dns.alpha.kubernetes.io/hostname

The external-dns pod checks the ingress (and/or services) for annotations and creates DNS records in upstream DNS provider.

Just insert your CloudFlare API key and email and create the respective service account (and ClusterRole and ClusterRoleBinding) and kubectl apply this!

Check the pod’s logs:

time=“2018–02–25T21:53:08Z” level=info msg=“Changing record.” action=CREATE record=gke-test.marekbartik.com type=A zone=11d584e02796b157bbfd81fccff0f5fa

Yay, it works!

Source repo with all the kubernetes resources necessary: https://github.com/bartimar/gke-external-dns-cloudflare

Check the external-dns tutorials for other cloud/dns providers like AWS, Azure, DigitalOcean and Google DNS, Route53 and so on.

--

--