0
0
Kubernetesdevops~30 mins

Service discovery via DNS in Kubernetes - Mini Project: Build & Apply

Choose your learning style9 modes available
Service discovery via DNS in Kubernetes
📖 Scenario: You are working with a Kubernetes cluster where multiple microservices need to find each other to communicate. Kubernetes provides a built-in DNS service that allows pods to discover services by their names.In this project, you will create a simple Kubernetes Service and a Pod that uses DNS to discover that Service by its name.
🎯 Goal: Build a Kubernetes Service named my-service and a Pod named my-pod that uses DNS to discover my-service by its name and prints the resolved IP address.
📋 What You'll Learn
Create a Kubernetes Service named my-service exposing port 80
Create a Pod named my-pod with a container running busybox
Configure the Pod to resolve my-service using DNS
Print the resolved IP address of my-service inside the Pod
💡 Why This Matters
🌍 Real World
In real Kubernetes clusters, services need to find each other by name to communicate. DNS-based service discovery is a core feature that makes microservices talk easily.
💼 Career
Understanding Kubernetes service discovery is essential for DevOps engineers and cloud-native developers to deploy and manage scalable applications.
Progress0 / 4 steps
1
Create a Kubernetes Service named my-service
Write a YAML manifest to create a Kubernetes Service named my-service that exposes port 80 and targets pods with label app: myapp. Use ClusterIP as the service type.
Kubernetes
Need a hint?

Use kind: Service and specify metadata.name as my-service. The selector should match pods labeled app: myapp. Expose port 80.

2
Create a Pod named my-pod with label app: myapp
Write a YAML manifest to create a Pod named my-pod with label app: myapp. The Pod should run a busybox container that sleeps for 3600 seconds.
Kubernetes
Need a hint?

Use kind: Pod with metadata.name as my-pod. Add label app: myapp. Use busybox image and command sleep 3600.

3
Add a command in the Pod to resolve my-service using DNS
Modify the busybox container command in my-pod to run nslookup my-service to resolve the service DNS name, then sleep for 3600 seconds.
Kubernetes
Need a hint?

Use command: ["sh", "-c", "nslookup my-service && sleep 3600"] to run DNS lookup and then keep the container alive.

4
Print the resolved IP address of my-service inside the Pod
Run the Pod and check the logs to see the output of nslookup my-service which shows the IP address resolved by Kubernetes DNS.
Kubernetes
Need a hint?

Use kubectl logs my-pod to see the output of nslookup my-service which includes the IP address.