Service Discovery
DNS is a built-in service launched automatically using the addon manager.
The addons are in /etc/kubernetes/addons directory on master node.
The DNS services can be used within pods to find other services running on the same cluster.
Every Service defined in the cluster (including the DNS server itself) is assigned a DNS name. By default, a client Pod’s DNS search list will include the Pod’s own namespace and the cluster’s default domain. This is best illustrated by example:
Assume a Service named foo in the Kubernetes namespace bar. A Pod running in namespace bar can look up this service by simply doing a DNS query for foo. A Pod running in namespace quux can look up this service by doing a DNS query for foo.bar.
The Pod spec also has an optional subdomain field which can be used to specify its subdomain. For example, a Pod with hostname set to “foo”, and subdomain set to “bar”, in namespace “my-namespace”, will have the fully qualified domain name (FQDN) “foo.bar.my-namespace.svc.cluster-domain.example”.
By default most Kubernetes clusters automatically configure an internal DNS service to provide a lightweight mechanism for service discovery. This default Kubernetes service is kube-dns service which enables Service Discovery.
Built-in service discovery makes it easier for applications to find and communicate with each other on Kubernetes clusters, even when pods and services are being created, deleted, and shifted between nodes.
The kube-dns service listens for service and endpoint events from the Kubernetes API and updates its DNS records as needed. These events are triggered when you create, update or delete Kubernetes services and their associated pods.
Multiple containers within one pod don’t need this service, as they can contact each other directly
A container in the same pod can connect the port of the other container direclty using localhost:port
To make DNS work, a pod will need a Service definition
nslookup of service2 from service1 will verify kube-dns service discovery.
DNS resolving can help in service discovery