Skip to content

Kubernetes Service discovery

Kubernetes service discovery is the mechanism by which applications (specifically [[Pods]]) locate and communicate with each other within a cluster. Instead of tracking the dynamic IP addresses of individual Pods, Kubernetes provides a stable abstraction—a [[Service]]—which acts as a network endpoint.

Service Abstraction

Pods in Kubernetes are ephemeral; their IP addresses change when they are restarted or rescheduled. To provide a stable network identity, Kubernetes uses a Service resource. A Service receives a stable IP address (ClusterIP) and DNS name, and it maintains a list of backend Pods (selected by labels) to forward traffic to.^[service.md]

DNS-Based Discovery

Kubernetes runs an internal DNS server where DNS records are automatically created for Services. This allows Pods to discover Services using standard naming conventions.

  • Service Name: Within the same namespace, Pods can reach a Service using its name, for example, nginx-deployment-service.^[service.md]
  • Fully Qualified Domain Name (FQDN): Services can also be reached using the full domain pattern <service-name>.<namespace>.svc.<cluster-domain> (typically <service-name>.<namespace>.svc).^[service.md]

This DNS configuration abstracts the underlying ClusterIP, allowing developers to reference logical service names in their code or configuration rather than hardcoding IP addresses.

Load Balancing

The Service resource also functions as a LoadBalancer. Traffic sent to the Service's IP or DNS name is automatically distributed across the healthy backend Pods associated with that Service.^[service.md]

  • [[Pods]]
  • [[Services]]
  • [[ClusterIP]]
  • NodePort

Sources

^[service.md]