Service DNS and headless discovery
Use names rather than Pod IPs
Cluster DNS lets applications locate Services by name. With the usual Pod DNS search configuration, a client in book-lab can use api; a client in a different namespace can use api.book-lab when its search configuration permits it. The fully qualified name includes the cluster DNS domain, which is configurable. These examples assume cluster.local and IPv4. Applications outside the cluster generally do not use this private DNS configuration automatically.
api.book-lab.svc.cluster.local. A 198.51.100.10http://api:80/catalogThe DNS record illustrates the virtual IP for the normal Service. A client uses the Service port; DNS does not encode the HTTP path. The trailing dot marks an absolute DNS name. No DNS query or HTTP request was performed.
Headless discovery returns backend addresses
Some applications need to choose individual peers instead of connecting through a Service virtual IP. A headless Service sets clusterIP to the string None, which disables allocation of that virtual IP. With a selector and ordinary readiness behavior, its DNS answers identify ready endpoints. Clients must handle address selection, caching, failed peers and changing membership. The Service does not supply virtual-IP load balancing for these direct connections.
apiVersion: v1kind: Servicemetadata: name: api-peers namespace: book-labspec: clusterIP: None selector: app: api ports: - name: http port: 8080 targetPort: 8080The normal API Service maps 80 to 8080. This separate headless example advertises 8080, the actual backend listener. When making direct connections using A/AAAA records, use the backend listener port; ordinary address records do not translate ports. The same Pod can be selected by more than one Service.
Distinguish aliases from endpoint discovery
ExternalName is useful for giving an external hostname a Service-style alias. Cluster DNS returns a CNAME, with no automatic proxy or port translation. HTTP Host and TLS certificate name checks still apply to the hostname used by the client. Never disable certificate validation to make an alias work. The sample target is intentionally unresolvable.
apiVersion: v1kind: Servicemetadata: name: partner-api namespace: book-labspec: type: ExternalName externalName: partner.example.invalidThis is a fictional example, not a connection to a real partner. With a normal cluster DNS setup the alias would point to partner.example.invalid; resolution of that reserved target cannot provide a working service.
Read the result, not just the name
An A record contains an IPv4 address and an AAAA record contains an IPv6 address. Named Service ports can also have SRV records that describe a target and port. Successful DNS resolution proves only that a name has been resolved, not that an application responds. Empty headless answers can reflect missing ready endpoints; stale cached answers can outlive a Pod. Investigate DNS, EndpointSlices, ports, network policy and application health as separate layers.
Practice: compare three answers
Read lab-fixtures/services/dns-cases.json. Classify each answer as a virtual IP, direct backend address or alias. Explain why the headless client uses port 8080 and what happens conceptually if its ready Pod changes. This concludes Services and service discovery. Next: ConfigMaps, Secrets and configuration.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Service DNS and headless discovery — knowledge check
Apply the lesson concepts to original offline scenarios.
What does a normal IPv4 ClusterIP Service DNS A record represent?
What makes a Service headless?
The headless answer is a backend IP whose listener is 8080. Which direct connection port should a client use?
Why might a short Service name resolve differently in another namespace?
An ExternalName alias resolves, but HTTPS reports a hostname mismatch. What is appropriate?