Configuring and working with Kubernetes DNS


Kubernetes is a powerful container orchestration platform that simplifies the management of containerized applications. One critical aspect of running applications on Kubernetes is the domain name system (DNS). In this article, we will explore the configuration and working of Kubernetes DNS in detail.

Understanding Kubernetes DNS

The domain name system (DNS) is a fundamental part of networking that translates human-readable domain names into IP addresses. In the context of Kubernetes, the DNS service enables communication between various components of the cluster using domain names instead of IP addresses.

Kubernetes DNS provides a simple and elegant solution for discovering services within a cluster. It allows services to be accessed using their registered names and provides automatic load balancing and service discovery capabilities.


By default, Kubernetes sets up a DNS service named "kube-dns" upon cluster creation. This DNS service consists of multiple components working together: a DNS server, a DNS config map, and a DNS autoscaler.

To configure Kubernetes DNS, you will need to modify the DNS config map to specify the domain names and IP addresses used within your cluster. The DNS config map is usually named "kube-dns" in the "kube-system" namespace.

Here's an example of a DNS config map:

apiVersion: v1
kind: ConfigMap
  name: kube-dns
  namespace: kube-system
  upstreamNameservers: |
    ["", ""]
  stubDomains: |
    {"": ["", ""]}

In the above example, we configure the upstream nameservers to be Google's public DNS servers ( and We also define a stub domain for "" with two IP addresses ( and

Once you've made the necessary configuration changes, you can apply the new DNS config map using the kubectl apply command:

kubectl apply -f dns-configmap.yaml

Working with Kubernetes DNS

Kubernetes DNS allows you to communicate with various services and resources within a cluster using their registered domain names. You can use the domain name in the following formats:

  • <service-name>.<namespace>.svc.cluster.local: This format allows you to access services within the same namespace.

  • <service-name>.<namespace>.svc.<cluster-domain>: This format enables access to services across different namespaces within the cluster.

For example, if you have a service named "my-service" in the "default" namespace, you can access it using the domain name "my-service.default.svc.cluster.local".

Additionally, Kubernetes DNS automatically assigns a DNS record to each service when it is created, following the format <service-name>.<namespace>.svc. These records are A records that point to the IP addresses of the corresponding service's pods.


Configuring and working with Kubernetes DNS is an essential aspect of deploying applications on a Kubernetes cluster. By properly configuring the DNS service and leveraging its capabilities, you can ensure seamless service discovery and communication within your cluster. Understanding the domain name formats and how to access services using DNS names is crucial for developing and operating applications in a Kubernetes environment.

noob to master © copyleft