Full lesson
Explore the full explanation, examples, and visuals at your own pace.
From inside a client Pod
You can't ping a Kubernetes Service. And that's fine. From inside a client Pod, three pings to 10.96.12.34 all vanish, a hundred percent packet loss. Yet the app calls http://web:80 and gets answers the whole time. The address isn't broken. Ping is simply testing it the wrong way.
$ ping -c 3 10.96.12.34
PING 10.96.12.34 (10.96.12.34): 56 data bytes
--- 10.96.12.34 ping statistics ---
3 packets transmitted, 0 packets received, 100% packet loss
# meanwhile, the app's calls to http://web:80 succeedSame Service IP, two very different results
Look at the two panels. On the left, ping sends an ICMP packet to 10.96.12.34, and it just fades out. No reply, and no Pod behind it. On the right, curl to web on port 80 goes through the same IP and lands on a Pod at port 8080, and a response comes back. The difference is the port.
No machine owns 10.96.12.34
No machine actually owns that Service IP. It's virtual. kube-proxy programs rules on each node that match the IP plus TCP port 80, then rewrite the destination to a web Pod on port 8080. Ping is ICMP and has no port, so no rule matches. Some networking setups do answer ping, though.
Test the port, not the IP
So test the port instead. Running curl against http://web:80 checks DNS, the forwarding rule, and a Pod in one go. A 200 OK means all three work. If it fails, run kubectl get endpoints web. That shows whether any Pods back the Service, here two on port 8080.
$ curl -sI http://web:80
HTTP/1.1 200 OK
# no answer? check Pods are actually behind it
$ kubectl get endpoints web
NAME ENDPOINTS AGE
web 10.244.1.7:8080,10.244.2.4:8080 5mA Service isn't a machine. It's a forwarding rule.
A Service isn't a machine. It's a forwarding rule. So when you check one, test it on its declared port, not with ping.
