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
