Course contentsShow
← Cloud and Infrastructure
Lesson 1206 of 2,98924. Kubernetes NetworkingFree lesson

Service Discovery with DNS

Leveraging CoreDNS for automatic service discovery using fully qualified domain names in the cluster.

Service Discovery with DNS

What you'll learn: How Kubernetes automatically creates DNS records so Pods can find Services by name instead of hardcoded IP addresses.

The Problem DNS Solves

Imagine running a web application that needs to connect to a database. In a dynamic cluster, Pod IPs change constantly as they restart or scale. Hardcoding an IP address would break immediately. You need a stable, human-readable way to find services.

DNS-Based Service Discovery

Kubernetes runs CoreDNS (which you encountered earlier in the architecture) as a built-in DNS server. Whenever you create a Service, CoreDNS automatically creates DNS records for it. Pods can then query these names to discover Services.

How It Works

When you create a Service named my-database in the production namespace, CoreDNS generates a fully qualified domain name (FQDN):

my-database.production.svc.cluster.local

Any Pod in your cluster can now reach that Service using this name. Kubernetes resolves it to the Service's ClusterIP automatically.

Shorter Names Within the Same Namespace

If your Pod is in the same namespace as the Service, you can use shortcuts:

  • Just the service name: my-database
  • With namespace: my-database.production

The DNS resolver automatically appends the rest based on the Pod's namespace.

The Analogy

Think of DNS like a phone book for your cluster. Instead of memorizing everyone's phone number (IP address), you just look up their name. CoreDNS maintains this directory automatically—no manual updates needed.

Key Takeaway: CoreDNS enables automatic service discovery by translating Service names into FQDNs that resolve to ClusterIPs, allowing Pods to connect using stable, readable names instead of ephemeral IP addresses.