Skip to main content
In this lab, we examine how CoreDNS integrates with a Kubernetes cluster while exploring various DNS and service connectivity scenarios. Follow along with the steps and command outputs provided below.

Identifying the Cluster DNS Solution

Begin by setting an alias for kubectl:
Then, list all pods in the kube-system namespace to identify the DNS solution in use:
From the output, it is clear that CoreDNS is the DNS solution running in this cluster.

Counting the DNS Server Pods

To determine the number of DNS server pods deployed, run:
There are two CoreDNS pods deployed within the cluster.

Discovering the DNS Service

Identify the service used to access CoreDNS by listing services in the kube-system namespace:
The service is named kube-dns and its Cluster IP is 10.96.0.10. This IP address must be configured on all pods for proper service resolution:

Configuring CoreDNS and the Corefile

File Location and Mounting

The CoreDNS container is initiated with an argument that points to its configuration file located at:
The pod specification reveals that the Corefile is mounted into the container via a volume configured by a ConfigMap:

Name of the ConfigMap

Inspect the volume configuration to see how the Corefile is provided:
When describing the ConfigMap, you might notice slight inconsistencies in naming as seen in the outputs:
Note that the ConfigMap names in the outputs differ slightly. Despite this inconsistency, both refer to the ConfigMap used for CoreDNS configuration.

Configured Root Domain

The Corefile provided by the ConfigMap includes the DNS configuration block for Kubernetes:
This indicates that the default domain (zone) configured in the cluster is cluster.local.

Exploring Pod and Service Connectivity

Multiple applications have been deployed in various namespaces. In the default namespace, you have pods like HR, simple-webapp, and test. In the payroll namespace, a pod named web is running. Verify their statuses:

In the Default Namespace

In the Payroll Namespace


Accessing the HR Web Server

Inspect the services in the default namespace to determine how the test pod can reach the HR web server:
Describing the web-service reveals its selector that directs traffic to pods labeled name=hr:
From within the test pod, you can resolve the HR web server using the service name web-service (or its fully qualified domain name in the default namespace). Remember that an intentionally incorrect name, such as web-service.default.pod, will not resolve.

Accessing the Payroll Service

For services deployed in a non-default namespace, you must use the fully qualified domain name that includes the namespace. In the payroll namespace, the web service is defined as:
Describing the payroll web service further confirms the configuration:
From the test pod in the default namespace, access the payroll service using its fully qualified domain name. Valid addresses include web-service.payroll or web-service.payroll.svc.cluster.local. Using an incorrect or incomplete name—for instance, web-service.payroll.svc.cluster (omitting the final “.local”)—will result in a resolution error.

Deploying a Web App That Connects to a MySQL Database

A web application is deployed that accesses a MySQL database. Inspect the current deployment:
When describing the deployment (e.g., using kubectl describe deploy webapp), you’ll notice the container’s environment variables:
  • DB_Host: mysql
  • DB_User: root
  • DB_Password: paswrd
If the MySQL service is running in the payroll namespace, using just “mysql” as the hostname will not resolve from a pod in the default namespace. Use the fully qualified domain name instead.
To correct this, update the deployment so the DB host includes the namespace. For example, change it to mysql.payroll (or mysql.payroll.svc.cluster.local). Edit the deployment with:
Then update the environment variables in the container specification:
After saving, Kubernetes will update the deployment, ensuring that new pods correctly resolve the MySQL service.

Verifying DNS Resolution with nslookup

From the HR pod, verify DNS resolution using nslookup.

Checking an Incorrect Hostname

First, run nslookup for the incorrect hostname:
Since the MySQL service is in the payroll namespace, this lookup fails.

Checking the Correct Hostname

Run nslookup for the fully qualified hostname:
To save the output to a file, execute:
Verify the file contents:

That concludes this lab. By following these steps, you have verified CoreDNS settings, confirmed service connectivity across namespaces, and ensured proper service name resolution so that your web application can connect to its MySQL database. Thank you for following along.

Watch Video