Hello and welcome to this lecture. In this lecture
we will discuss about DNS in the Kubernetes cluster. If you are new to DNS
make sure you go through the prerequisite section on DNS where we discuss what DNS is,
what are the tools used for working with DNS such as host, NS Lookup and dig utility and the different
types of DNS records like A, CNAME etc.
And we also saw how to setup our own DNS server using CoreDNS.
In this lecture we will see what names are assigned to what objects, what our service DNS records, POD
DNS records,
What are the different ways you can reach one part from another. In the next lecture,
we will see how Kubernetes implements DNS in the cluster. So we have a 3 node kubernetes cluster
with some PODs and services deployed on them.
Each node has a nodename and IP address assigned to it.
The node names and IP addresses of the cluster are probably registered in a DNS server in your organization.
Now how that is managed who accesses them are not of concern
in this lecture. In this lecture we discuss about DNS resolution within the cluster between the different
components in the cluster such as PODs and services. Kubernetes deploys a built-in DNS server by default
when you setup a cluster. If you setup kubernetes manually, then you do it by yourself.
We will see how that is done and how it is configured in the next lecture.
As far as this lecture is concerned we will see how it helps pods resolve other pods and services
within the cluster. So we don't really care about
nodes. We focus purely on PODs and services within the cluster. As long as our cluster networking is set
up correctly, following the best practices we learned so far in this section, and all pods and services
can get their own IP address and can reach each other.
We should be good.
Let’s start with just two PODs and a service.
I have a test pod on the left with the IP set to 10.244.1.5. And I have a web pod
on the right, with the IP set to 10.244.2.5. Looking at their IPs,
you can guess that they are probably hosted on two different nodes. But that doesn’t matter, as far
as DNS is concerned.
We assume that all PODs and services can reach other using their IP addresses. To make the web
server accessible to the test pod,
we create a service. We name it
Web service.
The service gets an IP 10.107.37.188. Whenever a service is created, the kubernetes DNS service creates
a record for the service. It maps the service name to the IP address. So within the cluster any pod can
now reach the service using its service name.
Remember we talked about name spaces earlier. That everyone within the namespace address each other just
with their first names and to address anyone in another namespace you use their full names ?
In this case since the test pod and the web pod and its associated service are all in the same namespace.
The default namespace. You were able to simply reach the web-service from the test pod using just the
service name web service.
Let's assume the web service was in a separate namespace named apps. Then to refer to it from the default
namespace.
you would have to say web-service.apps. The last name of the service is now the name of the namespace.
So here web service is the name of the service and apps is the name of the namespace. For each namespace
The DNS server creates a subdomain. All the services are grouped together into another subdomain called
SVC.
So what was that about?
Let's take a closer look.
web-service is the name of the service and apps is the name of the namespace. For each namespace
the DNS server creates a subdomain with its name. All pods and services for a namespace are thus grouped
together within a subdomain in the name of the namespace.
All the services are grouped together into another subdomain called svc.
So you can reach your application with the name web-service.apps.svc.
Finally, all the services and PODs are grouped together into a root domain for the cluster, which is
set to cluster.local by default. So you can access the service using the URL
web-service.apps.svc.cluster.local. And that’s the fully qualified domain name for the service.
So that's how services are resolved within the cluster.
What about PODs? Records for PODs are not created by default. But we can enable that explicitly,
We will see that in the next lecture. Once enabled,
Records are created for pods as well.
It does not use the POD name though. For each POD kubernetes generates a name by replacing the dots
in the IP address with dashes.
The namespace remains the same and type is set to pod. The root domain is always cluster.local.
Similarly the test POD in the default namespace, gets a record in the DNS server, with its IP converted
to a dashed hostname 10-244-1-5 and namespace set to default, type is POD
and root is cluster.local.
This resolve to the IP address of the POD.