DNS in Kubernetes

DNS in Kubernetes

Kubernetes DNS model

Usually CoreDNS is used for cluster DNS

DNS record (A) for a service:

DNS record (A) for a pod with IP

Add DNS server for custom domains

Services Internals 1/

Services hide infrastructure

Type ClusterIP

Service implements a load balancer

DNS record for service name is created

Type NodePort

Services exposes ports on node

Default port range is 30000-32767

Type LoadBalancer

Service integrated with cloud provider’s load balancer

Services Internals 2/2

Services hide infrastructure

Type ExternalName

Maps cluster IP and DNS record to well-known name

For example, central database server

ClusterIP=None (headless service)

No cluster IP

No load balancing

DNS A records for all matched pods

Demo: Headless Services

Understand how they work

ClusterIP Yes No Resolves to cluster IP
None No Yes Resolves to all pod IPs