liveBook · Manning

SRV record

As explained in Kubernetes in Action, Second Edition

An SRV record is a DNS record that identifies the host and port for a service, along with its protocol and priority information.

An SRV record is a DNS record that identifies a service’s protocol, port, target host, and priority information. In Kubernetes, each named Service port receives an SRV record in the cluster DNS, allowing clients to discover how to connect without hard-coding port details. section 11.4 section 11.4.1

Kubernetes service discovery uses SRV records in these ways:

  • A smart client can query a Service’s SRV records to discover the ports it provides. section 11.4.1
  • Named ports produce names in the form _port-name._port-protocol.service-name.namespace.svc.cluster.local. section 11.4.1
  • A headless Service associated with a StatefulSet gives stateful Pods SRV records that clients can use to discover each Pod’s address and port. section 16.1.5

Looking up a named Service port

Run a temporary tools Pod, then query the SRV record for the http port: kubectl run -it --rm dns-test --image=giantswarm/tiny-tools, followed by nslookup -query=SRV _http._tcp.kiada. The result identifies TCP port 80 on the kiada Service.

MongoDB discovery through SRV

A MongoDB client can use mongodb+srv://quiz-pods.kiada.svc.cluster.local instead of listing every replica address and port. The client performs an SRV lookup for _mongodb._tcp.quiz-pods.kiada.svc.cluster.local. section 16.1.5

How Kubernetes in Action, Second Edition covers it

How deep it goes
Explains the record format, lookup commands, named ports, and StatefulSet usage, while deferring general DNS implementation details.
Examples
Uses nslookup and dig queries, a temporary DNS-tools Pod, named HTTP and HTTPS ports, and a MongoDB SRV connection string.
What it assumes
Assumes basic Kubernetes Services and cluster DNS, then demonstrates DNS inspection from a temporary Pod.
What you can do after
Diagnose service discovery with nslookup or dig and configure clients to discover Kubernetes service ports through SRV lookups.
How it connects
Connects SRV records to DNS, Kubernetes Services, headless Services, StatefulSets, and MongoDB clients.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Kubernetes in Action, Second Edition. The section links point to the parts of the book it draws on.