0
0
Kubernetesdevops~20 mins

Service discovery via DNS in Kubernetes - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
DNS Service Discovery Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
How does Kubernetes DNS service discovery work?

In Kubernetes, how does the DNS service discovery mechanism help pods find other services?

APods use DNS names that resolve to service cluster IPs, allowing communication without hardcoding IPs.
BPods communicate only via static IP addresses assigned manually to each pod.
CPods use environment variables only to discover other services, DNS is not involved.
DPods must use external DNS servers to resolve service names outside the cluster.
Attempts:
2 left
💡 Hint

Think about how pods avoid using fixed IPs and still find services dynamically.

💻 Command Output
intermediate
2:00remaining
Output of DNS lookup inside a pod

What is the output of the following command run inside a pod in Kubernetes?

nslookup my-service.default.svc.cluster.local
Anslookup: can't resolve 'my-service.default.svc.cluster.local'
B
Name: my-service.default.svc.cluster.local
Address: 10.96.0.1
C
Name: my-service
Address: 192.168.1.1
DError: command not found
Attempts:
2 left
💡 Hint

Consider the default cluster IP range and DNS naming conventions.

Configuration
advanced
3:00remaining
Correct DNS configuration for a headless service

Which YAML snippet correctly defines a headless service to enable DNS-based service discovery of individual pods?

A
apiVersion: v1
kind: Service
metadata:
  name: my-headless
spec:
  type: LoadBalancer
  selector:
    app: myapp
  ports:
  - port: 80
B
apiVersion: v1
kind: Service
metadata:
  name: my-headless
spec:
  clusterIP: 10.96.0.10
  selector:
    app: myapp
  ports:
  - port: 80
C
apiVersion: v1
kind: Service
metadata:
  name: my-headless
spec:
  clusterIP: None
  selector:
    app: myapp
  ports:
  - port: 80
D
apiVersion: v1
kind: Service
metadata:
  name: my-headless
spec:
  externalName: myapp.example.com
  ports:
  - port: 80
Attempts:
2 left
💡 Hint

Headless services have no cluster IP to allow direct pod DNS entries.

Troubleshoot
advanced
2:30remaining
Troubleshooting DNS resolution failure in a pod

A pod cannot resolve the DNS name of a service inside the cluster. Which is the most likely cause?

AThe pod's container image is missing the nslookup tool.
BThe pod is using hostNetwork: true.
CThe service has no ports defined in its spec.
DThe CoreDNS pods are not running or have crashed.
Attempts:
2 left
💡 Hint

DNS resolution depends on a running DNS server inside the cluster.

🔀 Workflow
expert
3:00remaining
Order the steps to verify DNS-based service discovery in Kubernetes

Put these steps in the correct order to verify DNS-based service discovery inside a Kubernetes cluster.

A2,4,1,3
B2,1,4,3
C1,2,4,3
D4,2,1,3
Attempts:
2 left
💡 Hint

Start by checking cluster components, then run tests inside pods.