liveBook · Manning

Service discovery

As explained in Kubernetes for Developers

Service discovery is the process of locating available services and their network endpoints within a distributed system.

Service discovery locates a Service’s current network endpoint without hardcoding its cluster IP into application code. This keeps deployments portable across development, staging, and production environments. section 7.1.3

Kubernetes provides two discovery mechanisms:

  • DNS works across the cluster. An application can address the Service by name, such as http://robohash-internal. section 7.1.3
  • Environment variables expose a Service’s cluster IP and ports inside Pods in the same namespace. They are fast and have no dependency on an external DNS server. section 7.1.3
  • Environment-variable discovery requires the Service to exist before the Pod is created, and changed values may require restarting the Deployment’s Pods. section 7.1.3

A Service supplies the stable cluster-local address that discovery resolves, while also routing traffic only to running Pods selected by its labels. Services can therefore connect independently scaling applications in a cluster. section 7.3 section 3.2.5

Calling an internal avatar service

A timeserver Deployment can set AVATAR_ENDPOINT to http://robohash-internal and have its application request that endpoint when serving /avatar. The same configuration can instead use ROBOHASH_INTERNAL_SERVICE_HOST when environment-variable discovery is appropriate.

How Kubernetes for Developers covers it

How deep it goes
Explains DNS and environment-variable mechanisms, scope, ordering, and restart implications, but does not detail DNS internals.
Examples
Demonstrates timeserver-to-robohash calls through DNS, environment variables, Deployment YAML, and kubectl inspection.
What it assumes
Assumes Kubernetes Pods and Services; teaches endpoint lookup, namespace scope, and Service-to-Pod routing through concrete deployments.
What you can do after
Apply it via Kubernetes DNS names or Service environment variables to configure portable inter-application calls.
How it connects
Connects Kubernetes Services with Pods, namespaces, DNS, environment variables, load balancing, and Ingress.

Also explained in

Compare how 7 books explain service discovery →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Kubernetes for Developers. The section links point to the parts of the book it draws on.