π§ Kubernetes Service Connectivity: nslookup vs curl¶
This guide explains the difference between nslookup and curl when testing Kubernetes Services β what each one checks, when to use which, and how to interpret the results during CKAD/CKA exams.
π§© 1. The Two Layers of Service Access¶
When you test a Kubernetes Service from inside a pod, youβre checking two separate layers:
| Tool | Layer Tested | Purpose |
|---|---|---|
nslookup | DNS (CoreDNS) | Checks if the Service name resolves to a ClusterIP |
curl | Network + Application | Checks if traffic can reach the Service and the app responds |
βοΈ 2. Example Commands¶
β DNS Test¶
nslookup nginx-svc.default.svc.cluster.local
Example output:
Name: nginx-svc.default.svc.cluster.local
Address: 10.96.12.101
β Application Test¶
curl nginx-svc.default:80
Example output (for Nginx):
<html>
<head><title>Welcome to nginx!</title></head>
<body>...</body>
</html>
π§ 3. Difference in Depth¶
| Command | What it Tests | What Success Means |
|---|---|---|
nslookup svc-name.ns.svc.cluster.local | CoreDNS DNS resolution | Service name β ClusterIP works |
curl svc-name.ns:port | Network + application path | Service + Pod connectivity works |
Analogy:¶
nslookup= finding someoneβs phone number πcurl= actually calling them and getting a reply π
π§© 4. How Kubernetes Resolves Names¶
Inside any pod, /etc/resolv.conf includes:
search ns.svc.cluster.local svc.cluster.local cluster.local
nameserver 10.96.0.10
When you type:
curl amor.amor:80
amor.amor.svc.cluster.local
π§° 5. How to Interpret Results in Exams¶
nslookup Result | curl Result | Meaning |
|---|---|---|
| β Works | β Works | Everything is healthy |
| β Fails | β Fails | DNS/CoreDNS issue |
| β Works | β Fails | NetworkPolicy issue / wrong target port / no endpoints |
| β Fails | β Works | Misconfiguration (rare) |
π§© 6. Example CKAD Workflow¶
# Step 1: DNS Resolution Test
kubectl exec testpod -n alpha -- nslookup nginx-svc.alpha.svc.cluster.local
# Step 2: Application Connectivity Test
kubectl exec testpod -n alpha -- curl nginx-svc.alpha:80
Result Meaning:¶
- Both β β Service fully functional
- nslookup β but curl β β Routing or app issue
- Both β β DNS/CoreDNS issue
β‘ 7. Common Exam Scenarios¶
| Exam Prompt | You Should Run | Layer Tested |
|---|---|---|
| βVerify if service name resolvesβ | nslookup svc-name.ns.svc.cluster.local | DNS |
| βCheck if the pod can access the serviceβ | curl svc-name.ns:port | Application |
| βService resolves but not reachableβ | Both commands | DNS + Network |
| βPods canβt reach app even though DNS worksβ | curl only | NetworkPolicy or wrong port |
π§ 8. Flowchart for Debugging¶
ββββββββββββββββββββββββββββ
β Run nslookup β
β (Check DNS resolution) β
ββββββββββββββ¬ββββββββββββββ
β
βββββββββββββ΄ββββββββββββ
β β
Works β
Fails β
β β
βββββββββββ΄ββββββββββ ββββββ΄ββββββββββ
β Run curl β β Fix DNS/CoreDNS β
β (Check app reach) β β or Service name β
βββββββββββ¬ββββββββββ ββββββββββββββββββ
β
βββββββββ΄βββββββββ
β β
Works β
Fails β
β β
β ββββββββββββ΄ββββββββββββ
β β Check NetworkPolicy β
β β Ports / Endpoints β
β ββββββββββββββββββββββββ
π§ 9. Quick Reference Table¶
| Test Goal | Command | What It Proves |
|---|---|---|
| Check DNS resolution | nslookup svc-name.ns.svc.cluster.local | CoreDNS is resolving names |
| Check Service routing | curl svc-name.ns:port | Service forwards traffic correctly |
| Check ClusterIP access | curl <ClusterIP>:<port> | Network path works (bypass DNS) |
| Test both layers | Run both commands | Full connectivity verified |
β€οΈ 10. Summary (for CKAD Mindset)¶
| Command | Focus | Layer |
|---|---|---|
nslookup | βCan I find the service?β | DNS (CoreDNS) |
curl | βCan I reach and talk to it?β | Network + App |
Rule of thumb:
πΉ If
nslookupfails β DNS problem.
πΉ Ifnslookupworks butcurlfails β NetworkPolicy or wrong port.
πΉ If both work β everything is fine.