Skip to content

When performing many DNS lookups in Kubernetes, Envoy becomes "stuck" to one DNS pod #7965

Closed

Description

@jpvowen

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:

  1. 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.
  2. 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.

  1. 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 nat rules to route packets to various pods. iptables' nat rules 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 the nat tables before getting routed.
  2. 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

  1. added
    enhancement
    help wanted
    on Aug 19, 2019
  2. mattklein123 commented on Aug 19, 2019

    @mattklein123
    Member

    Sounds like a reasonable request: marking enhancement/help wanted.

  3. nezdolik commented on Sep 2, 2019

    @nezdolik
    Member

    @mattklein123 could help with this one.

  4. mattklein123 commented on Sep 3, 2019

    @mattklein123
    Member

    Thanks @nezdolik!

  5. nezdolik commented on Oct 11, 2019

    @nezdolik
    Member

    heads up, am starting to actively work on this

  6. added a commit that references this issue on Dec 4, 2019
    b78fc4e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancementhelp wanted

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions