DNS Records and FQDN

A lookup for a Service can come back as one address, as a list of Pod addresses or with a port attached, and a single Pod can have a name too. What decides the shape of the answer the cluster DNS gives?

Play the animation 5 steps, animated, plays on a computer or a tablet

DNS Records and FQDN diagram: Kubernetes DNS records

DNS Records and FQDN, step by step

  1. The full name is web.default.svc.cluster.local: the Service, its namespace, the literal svc, then the cluster domain. Under the default ClusterFirst policy a Pod resolv.conf carries search domains and ndots:5, so a short name like web is expanded to this fully qualified form before it leaves the Pod. Every record below is a variation on these four segments.

    Play from step 1
  2. A query for the name itself gets an A record, or AAAA on IPv6, pointing at the Service ClusterIP, 10.96.0.20. This is the common case: the name resolves to the stable virtual IP, and the Service rules kube-proxy writes send traffic on to one Pod. The address answered is the web Service, not the kube-dns ClusterIP the question was sent to.

    Play from step 2
  3. A named port also publishes an SRV record. The name grows a prefix, _http._tcp, naming the port and the protocol, and the answer carries the port number and the target host. It lets a client discover which port a Service exposes without that port number being hard-coded in the client.

    Play from step 3
  4. If the Service is headless, the client asks the same name it asked for the A record and gets a different answer: one A record per ready Pod instead of a single virtual IP, here three of them, and the client chooses an endpoint itself.

    Play from step 4
  5. Finally a Pod has a record of its own, a form that predates the DNS spec, and here the name changes twice: the Pod IP written with dashes takes the place of the Service, and the subdomain flips from svc to pod. CoreDNS only serves it when the kubernetes plugin has pods enabled, which kubeadm sets to insecure by default, and in that mode CoreDNS answers from the name without checking that such a Pod exists. A stable way to reach one specific replica is a StatefulSet Pod hostname under a headless Service.

    Play from step 5

Sources