Updated April 15, 2023
Introduction to Kubernetes DNS
DNS in Kubernetes or in general stands for Domain Name System which consist of various type of information which is easy to read and understand. This information generally includes the IP address which is replaced by the easy to remember the name in place. In Kubernetes, if we see most of the cluster but default enables the domain service and helps us to provide the lightweight mechanism for service discovery. But if we see the implementation of DNS in Kubernetes is changing over time, which we can see in the latest or recent version of Kubernetes. Whatever the service we defined in the cluster is associated with the DNS name. In the coming section of the article, we will see the internal implementation of DNS in Kubernetes with detailed explanations to understand how it works for better clarity and understanding.
Kubernetes DNS Service
As we already saw and discussed that internal implementation of the Kubernetes DNS service is changing over the latest version of Kubernetes. In this section, we will have a detailed understanding of the working of DNS service. So basically Kubernetes allows us to create a group of containers and by that, we can able to define the service on top of that. All these services are assigned a static Ip address, so in order to resolve this IP address internally, Kubernetes also try to generate the DNS that will help to resolve this IP address. Also, Kubernetes create the NS for pods and service, so we know that the service is associated with the IP address, so instead of using the IP address to contact the service, we can also use the DNS name which is generated by the Kubernetes which is easy to remember than the Ip address. We have two types of objects in the DNS record which are discussed below;
1) service
2) pods
Let’s discuss each of them in detail;
1) Service: So each of the services assigns with a DNS record, which can be DNS A or AAAA , this is totally depends on the Ip of the service that is the IP family. So these services are associated with DNS records A /AAAA.
Also without the cluster Ip address, these services are assigned with a DNS record which is again a A/AAAA, depends majorly on the IP family of the service. The one that we have discussed above is termed as ‘Normal’ or ‘not headless’ and the second one is termed as ‘Headless’. which can be represented by the below example :
e.g. :
my-svc.my-namespace.svc.cluster-domain.example
2) Pods: Now the second one we have is pods, it also has a basic DNS resolution structure in Kubernetes, suppose f the pods we have is n default namespace then the IP address for that pod will be ‘172.17.0.3’ and the associated domain name for the pods will be ‘cluster.local’. So after following the DN resolution structure defied already we can create the below;
structure : pod-ip-address.my-namespace.pod.cluster-domain.example
original : 172-17-0-3.default.pod.cluster.local
So this is a way to resolve the pod DNS name.
Create Kubernetes DNS and Example Kubernetes DNS
To create the Kubernetes DNS we can use the core DNS in the Kubernetes, so let’s take a look at all the configurations and mapping we have to make in order to create it, let’ get started to see below;
1) for this we have to maintain a core File, which contains a lot of configuration as key-value pair entry, this file is called as CoreDNS configuration file.
2) to install the CoreDNS run the below file,
e.g. :
DNS Core file to change how DNS service discovery behaves for that cluster.
In Kubernetes, CoreDNS is installed with the following default Corefile configuration:
apiVersion: v1
kind: ConfigMap
metadata:
name: coredns
namespace: kube-system
data:
Corefile: |
.:53 {
errors
health {
lameduck 5s
}
ready
kubernetes cluster.local in-addr.arpa ip6.arpa {
pods insecure
fallthrough in-addr.arpa ip6.arpa
ttl 30
}
prometheus :9153
forward . /etc/resolv.conf
cache 30
loop
reload
loadbalance
}
This is the standard file to install the CoreDNS.
2) this core file will give us the below plugin for CoreDNS;
- a) error
- b) health
- c) reload
- d) loop
- e) cache
- f) forward
- g) load balance
In this way, we can create DNS in Kubernetes by the use of CoreDNS.
Errors in the DNS
We may face various kinds of issues while using DNS for service or pods in Kubernetes but the general issue that we can face is described below;
1) we are unable to connect to the DNS service or IP address because we are not connected to the network or we have lost the internet access as well. Basically, DNS helps us to connect to the Ip address, associated with it.
2) Also in the other words it helps us to convert our domain name to the IP address, or translate our name to the Ip address or vice versa.
3) We can do basic troubleshooting for this to resolve this kind of issue for which we can take the below steps see below;
- a) try to reboot your router: Try to restart it, and wait for few minutes before restarting it.
- b) check the site: try to conform the DNS name for the particular website for which you are facing an error.
- c) try to check the connection and cables: if we are connected via Wi-Fi or lane we should first check if it is properly plugged in or not just to make sure it is working.
Also, try to check the service or pods are running which can be confirmed by the below command;
kubectl get pods
Conclusion
So in this article, we have seen the creation of DNS service in Kubernetes with an example also, follow the whole article instruction to get a better understanding about the DNS in Kubernetes, as we already know that why we use them in Kubernetes. This is easy to use, create, and maintainable. also, help the developer to resolve the IP address of the pods or service via their DNS name assigned to them.
Recommended Articles
We hope that this EDUCBA information on “Kubernetes DNS” was beneficial to you. You can view EDUCBA’s recommended articles for more information.