This lab explores CoreDNS integration with Kubernetes, focusing on DNS and service connectivity scenarios.
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.
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:
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.
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:
Copy
Ask AI
root@controlplane:~# k get svc -n payrollNAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGEweb-service ClusterIP 10.97.196.21 <none> 80/TCP 10mroot@controlplane:~#
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:
Copy
Ask AI
root@controlplane:~# k get deployNAME READY UP-TO-DATE AVAILABLE AGEwebapp 1/1 1 1 15sroot@controlplane:~#
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:
Copy
Ask AI
root@controlplane:~# k edit deploy webapp
Then update the environment variables in the container specification:
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.