DNS caching and forwarding in Cloud Foundry with Consul Agents
Hector Rivas Gandara
Recently we were investigating some DNS resolution errors in our CF
installation running CF v238 with consul-agent.
We found out some caveats and we would like to know your thoughts, how
you setup it and possible improvements.
I will assume CF v238  + Diego 0.1476.0  + consul-release 92
, running on AWS.
* the consul-release/consul-agent job will always configure consul as
* consul-agent is added in resolv.conf before the normal recursors.
The linux resolver will still query directly the recursor if consul
* consul forwarding capabilities are simple , compared with
bind/pdndsd/dnsmasq (eg. hardcoded timeout 2s, simply iterates each
recursor, no health monitoring, no caching/stale, no parallel
* it is not possible to customise the consul-agent DNS config (listen
port, disable forwarding, etc)
* consul-agent has not "serve stale" configured , so DNS interface
will fail during leader election . Also the query must be served by
* the recursor, AWS DNS, might timeout for some queries (as any DNS)
We think this setup is not really the most resilient one. The leader
election makes the resolution fail, consul timeouts in 2s but linux
does in 5s, linux might bypass the consul-agent, no stale serving,
We are considering some improvements on this situation:
1. Deploy some DNS forwarding+cache servers (eg bind),
- use them in front of AWS DNS doing caching
- they can delegate to the consul masters for
- Pros: central cache will have a better success rate.
- Cons: Another service/server to take care of.
2. Deploy a pdnsd/dnsmasq/bind in each node as local cache.
- Implement all the DNS local caching goodness (and badness)
- Can forward to the local consul-agent for *.services.cf.internal domains.
- We will need to change consul-release to allow use this.
3. Modify consul-release to allow enable stale caching, change DNS
configuration and change how resolv.conf is managed?
4. Enable serve DNS stale in consul, to avoid issues during leader election.
5. Do some PRs to consul to improve the DNS forwarding, adding some
cool features like pdnsd 
Our questions are:
* Do you have similar errors with DNS than us? (eg deployments
failing due DNS resolution errors)
* Is the current consul-release setup a desired configuration? is
there any documented architectural decision about this?
* Shall we use consul-agent as DNS forwarder at all?
* How do you deal with DNS caching? Do you use any local agent or
bind caching servers?
* Shall we enable serve stale in the consul-release?
* Is it right that the consul-agent changes and parses
/etc/resolv.conf in the start scripts? 
Bunch of links:
Hector Rivas | GDS / Multi-Cloud PaaS