Caching in CoreDNS
In the last couple of evenings I’ve implemented a caching middleware in CoreDNS. It has a only a few knobs and should be simple to use.
Take a simple Corefile and add caching, via the cache
directive.
Which defines CoreDNS to be a proxy, and only cache responses for the miek.nl
zone. This
cache only caches for up to 10 seconds. Lets send some queries and looks at the logs:
The 33.74ms is the upstream query duration for the first miek.nl
query, after that it craters to a
low value. This does not happen for google.com
as that domain is exempt from caching.
In the response the TTL is lowered as well:
With caching the last missing piece of SkyDNS has been implemented (only online DNSSEC signing is remaining). I believe (haven’t run CoreDNS in production yet), that CoreDNS has more features (notable multiple domain support) and is more standard compliant than SkyDNS. Having said that, SkyDNS allows its config to be stored in etcd and it can get config from environment variables. CoreDNS can receive a Corefile via stdin though.
The following Corefile should mimic SkyDNS completely: