Open In App

Kubernetes – Service DNS

Last Updated : 30 Mar, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

Pre-requisite:- Kubernetes

An open-source container orchestration system called Kubernetes is primarily employed for the automated deployment, scaling, and management of software. Another name for Kubernetes is K8s. Initially created by Google, Kubernetes is currently maintained by the Cloud Native Computing Foundation. Although it now supports both containers and CRI-O in addition to the Docker runtime with which it was first intended to communicate. Automating the operational chores of container management is Kubernetes’ primary goal. It has built-in commands for application deployment and rolling out necessary modifications to the application. Companies like Google, Spotify, and Capital One are now using it.

Introduction to DNS

DNS stands for Domain Name System. It is a system for giving different types of information with unique easy to remember names. It is useful to give a lightweight mechanism for service discoveries. Due to the built-in service discovery, it is easy for applications to communicate with each other in Kubernetes clusters. 

Services DNS

In Kubernetes DNS record is created for both Services and Pods. we can use consistent DNS names instead of IP addresses to contact services. After scheduling a DNS Pod and Service on the cluster, Kubernetes DNS instructs the kubelets to tell the individual containers to use the DNS Service’s IP to resolve DNS names. Every service that is defined in a cluster is given a DNS name, this includes the DNS server itself. The client Pod’s search list will include the Pod’s own name and cluster definition by default. 

Services Namespaces

A DNS query may return different results. The returned value is based on the namespace of the Pod that is making it. It is not specified by DNS queries that the namespace is limited to DNS queries. Think of a data service in the prod namespace and a pod in the test namespace. Due to the usage of the pod’s test name case, a query for data yields no results, while a query for data does. Prod produces the desired outcome because the namespace is provided there.

Kubernetes Implementation

we can set up a DNS system with two well-supported add-ons namely CoreDNS and KubeDNS. The CoreDNS feature is one of the best and latest add on and it acts as a default DNS server. Both the add-ons can schedule a DNS pod or pods or services with a static IO on the cluster and both are named as kube dns in the metadata. name field. 

Types of DNS Services

A Records

Normal services are assigned to a DNS A or AAAA record. For a name of the type my-svc.my-namespace.svc.cluster-domain.example, this will resolve to the cluster IP of the Service. This relies on the IP family of the Services.

Additionally, dependent on the IP family of the service, headless services are given a DNS A or AAAA record with the name of the format my-svc.my-namespace.svc.cluster-domain.example. This will resolve to the collection of pod IPs that the service has chosen.

file

 

SRV Records

They were primarily developed for named ports that were essential to Headless Services or regular services. Every named port will have an SRV record of the format _my-port-name. my-port-protocol.my-svc.my-namespace.svc.cluster-domain.example. This resolves to the port number and, in the case of a typical service, the domain name my-svc.my-namespace.svc.cluster-domain.example.

file

 

Features of DNS services

The main features of DNS services are:

  • It can be used to map to a new IP address if the host’s IP address is ever changed.
  • It is easier to remember when compared to the IP address.
  • It allows organizations to use a domain name hierarchy that is independent of any IP address provided.

Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads