10 DNS in Kubernetes

 

This chapter covers

  • Reviewing DNS in Kubernetes clusters
  • Exploring hierarchical DNS
  • Examining the default DNS in a Pod
  • Configuring CoreDNS

DNS has existed as long as the internet. Microservices make it hard to manage DNS records at scale because they require an explosion in the use of domain names on an internal data center. Kubernetes standards around DNS for Pods make DNS extremely easy, such that individual applications rarely need to follow complex guidelines for finding downstream services. This is generally enabled by CoreDNS (https://github.com/coredns/coredns), which is at the heart of this chapter.

10.1 A brief intro to DNS (and CoreDNS)

The job of any DNS server is to map DNS names (like www.google.com) to IP addresses (like 142.250.72.4). There are a few common mappings from DNS servers that we use every day when we browse the web. Let’s look at some of those.

10.1.1 NXDOMAINs, A records, and CNAME records

When using Kubernetes, DNS is mostly handled for you, at least in clusters. We still need to define a few terms to contextualize this chapter, however, especially in situations where you might have a custom DNS behavior you care about (for example, with headless services, as seen in this chapter). As for our definitions, at the very least, you’ll want to know about

10.1.2 Pods need internal DNS

10.2 Why StatefulSets instead of Deployments?

10.2.1 DNS with headless services

10.2.2 Persistent DNS records in StatefulSets

10.2.3 Using a polyglot deployment to explore Pod DNS properties

10.3 The resolv.conf file

10.3.1 A quick note about routing

10.3.2 CoreDNS: The upstream resolver for the ClusterFirst Pod DNS

10.3.3 Hacking the CoreDNS plugin configuration

Summary