🧠 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.