Repository navigation
Description
Description:
I've seen this when using Kubernetes with Flannel for the network fabric.
When an Envoy container is performing many DNS lookups (or when some DNS lookups become slow enough) that Envoy always has a request in-flight, Envoy becomes effectively "stuck" to the same dns pod, even when the DNS pod becomes slow or dies.
We have a cluster that has a lot of Envoy services exposed to it, with strict DNS / logical DNS resolution, and I've observed this cause two issues:
- With many containers performing health checks for a bunch of services, a small slowdown on one DNS pod causes envoy containers doing lookups for health checks to start "sticking" to the pod, increasing its load and eventually reaching the point where every DNS query by Envoy in the entire cluster is being routed to a single pod, which overloads.
- When a node with a DNS pod unexpectedly dies, Envoy continues making DNS requests at that node's now-nonexistent IP, causing DNS to timeout and Envoy to conclude that the service doesn't have any healthy endpoints.
This is caused by an interaction of the way Kuberenetes + Flannel do DNS routing, and the way c-ares handles UDP sockets.
- Kubernetes services don't trust endpoints to load-balance their requests evenly (See [https://kubernetes.io/docs/concepts/services-networking/#why-not-use-round-robin-dns]), so instead of telling pods about multiple IP addresses, it gives them a single endpoint for DNS and uses
iptables natrules to route packets to various pods.iptables'natrules get hit whenever a pod opens a new connection, and they route the connection randomly to a DNS pod. The somewhat surprising thing is that it also considers UDP to have "connections", even though it's a connectionless protocol - UDP packets going over an already-open socket to a IP+port that have been hit before don't hit thenattables before getting routed. - c-ares, which Envoy is using for DNS, uses the same socket for any requests to the same nameserver, provided one's already open. Since Kube only presents one IP address for DNS resolution, c-ares sees this as a single server, and uses the same socket for all requests, provided that it currently has some requests in flight. Moreover, c-ares ignores any timeouts and errors it gets on the UDP socket, so the socket doesn't close until c-ares isn't waiting for any requests.
Once you have an Envoy container making DNS requests (for service lookup or health checks) frequently enough that it always has at least one request in flight, it becomes "stuck" to its particular DNS pod, since it always has an open "connection" there from iptables' standpoint, and never hits the NAT tables that could send it to a different pod. This becomes more likely when a DNS pod is slow or dead and requests start timing out -- and even when a DNS pod dies and is rescheduled, there's never a chance for Envoy's DNS to hit the NAT table again and have the connection rerouted, so its DNS is still effectively down.
On Envoy's end, could you add a config option to force DNS over TCP (through the ARES_FLAG_USEVC flag)? This would solve some of these issues by giving a chance for connections to get killed when DNS is having issues.
[optional Relevant Links:]
Activity
mattklein123 commentedon Aug 19, 2019
Sounds like a reasonable request: marking enhancement/help wanted.
nezdolik commentedon Sep 2, 2019
@mattklein123 could help with this one.
mattklein123 commentedon Sep 3, 2019
Thanks @nezdolik!
nezdolik commentedon Oct 11, 2019
heads up, am starting to actively work on this
Introduce new config option for DNS over TCP (#8588)