Service Discovery on Kubernetes

Service Discovery on Kubernetes

  • The dns service can be used inside pod to locate other services operating on the same cluster.

  • Multiple containers within a pod do not require this service because they communicate directly with one another.

  • A container in the same pod can connect directly to the port of another container by using localhost:port

  • A pod will require service definition in order for DNS to function.

  • Assume there are two apps, with Pod 1 and Pod 2 each having one container with app1 and app2 service definitions. App 1's IP address is 10.0.0.1, while App 2's is 10.0.0.2. The dns can be examined.

$host app1-service
app1-service has address 10.0.0.1
$host app2-service
app2-service has address 10.0.0.2
  • If app1 needs to connect to app2, it can use a DNS query to find the app2-service. Both applications must be in the same namespace for this to work.

  • 'default' is the standard namespace. Pods and services can be launched in different namespaces to logically separate the cluster.