Enable Per-Pod DNS Records for a Deployment
Scenario
The mesh namespace runs a peer-server Deployment with 3 replicas backed by the httpd:alpine image.
The application relies on DNS-based peer discovery. Each peer-server instance performs a DNS lookup for peer-svc.mesh.svc.cluster.local, expecting to receive the IP address of every running peer-server pod so it can discover and connect to all of its peers.
Run the lookup from the netprobe Deployment to see what DNS currently returns:
kubectl exec deploy/netprobe -n mesh -- nslookup peer-svc.mesh.svc.cluster.local
You will see output similar to:
Server: 10.43.0.10
Address: 10.43.0.10#53
Name: peer-svc.mesh.svc.cluster.local
Address: 10.43.237.238
The Server: and Address: ...#53 lines identify the DNS server that handled the query, not a pod IP. The actual DNS result is the Address: line below the Name: field.
Only a single IP address is returned, regardless of how many peer-server pods are running. Instead of returning the IP address of each running peer-server pod, the DNS lookup returns only a single Service IP. As a result, the application cannot discover and connect to all running peer-server instances.
Task
Investigate the peer-svc Service in the mesh namespace. Determine why the DNS lookup returns only the Service virtual IP, then update the Service so that a lookup for peer-svc.mesh.svc.cluster.local returns the IP address of each running peer-server pod instead of the Service virtual IP.
Confirm the fix by re-running the nslookup command from the netprobe Deployment and verifying that the number of IP addresses returned matches the number of running peer-server pods.
Do not modify the peer-server Deployment or the netprobe Deployment.
Modify only the peer-svc Service.
Hint 1 - Understand How Kubernetes DNS Resolves Services
By default, Kubernetes assigns every Service a virtual IP. When a pod performs a DNS lookup for a service name, it receives that single virtual IP, not the IPs of the individual pods behind it.
There is a service configuration option that changes this behaviour entirely: instead of returning the virtual IP, DNS returns one record for each matching pod.
Read the service spec fields and the Kubernetes Service documentation to find which field controls this:
kubectl explain service.spec
kubectl describe svc peer-svc -n mesh
Documentation
Hint 2 - The Type of Service That Returns Per-Pod Records
Kubernetes has a specific mode for services where no virtual IP is assigned at all. In this mode, DNS bypasses the proxy layer and returns the IP of each individual pod directly.
This type of service is sometimes called a headless service. Research how it differs from a regular ClusterIP service and which field in the service spec you need to set to enable it.
Documentation
Hint 3 - Applying the Change
Some service fields are immutable once a service is created. You cannot patch them on a live object. If you try to edit the field directly and get an error, you will need to remove and re-create the service.
One way to do this without losing the existing spec:
kubectl get svc peer-svc -n mesh -o yaml > peer-svc.yaml
# Edit peer-svc.yaml with the required change
kubectl replace --force -f peer-svc.yaml
Documentation
Hint 4 - Confirming the Fix
After updating the service, re-run the DNS lookup from the network probe pod:
kubectl exec deploy/netprobe -n mesh -- \
nslookup peer-svc.mesh.svc.cluster.local
Then count the running pods the service should be routing to:
kubectl get pods -n mesh -l app=peer-server
If the number of Address: lines in the nslookup output matches the number of Running pods, the fix is working correctly.