Using what i learnt from the kubernetes course, I set up a simple experiment, where i have an nginx service (which exposes deployment nginx on port 1234 and 4 replicas) and then another separate pod running buysbox for 1 hour.
I exec -it into the Busybox pod and then tried pinging the clusterip’s ip address, but doesn’t ping.
I did:
I think the problem is that you can’t ping a service, which is a figment of a node’s firewall imagination. You can ping the IP of the underlying nginx pod – just tired it, works fine from busybox, which does have ping on it.
You can’t curl from busybox because most versions of busybox do not include curl; you’d need a different container to do that.
What does work, and well, is to use the netcat utility (nc) to hit your port. This will work if you exec it out from busybox:
Thanks, I tried replicating what you observed on my cluster and yes, like you pointed out in 1), i am indeed able to successfully ping a specific nginx pod from busybox pod.
However unlike 3) when i tried netcat command from within the busybox POD, connection keeps timing out. Is there a way to know whether connection was successful or not? I didn’t get a successful connection message.
Secondly,
A) Does the “nginx” in the nc -v -w5 nginx 1234 command refer to the nginx pod or nginx service or nginx deployment?
B) If i have 2 deployments both exposed as cluster-ip services (e.g. service1 and service2) , how to get the full URL with endpoint of service1 so that i can input it inside my python code of my application for service2 to make REST calls to make post requests etc?
There are two possibilities here. One is that the service is in fact not responsive on port 1234; you should do k get ep to check that there is in fact an endpoint behind the service. Second, nginx wants to deliver content at port 80 by default, so the target port of the service needs to be 80; port should be 1234 for the service.
To the service. Usual service naming requirements apply; if the service is called “nginx”, then you can call it (for namespace default) nginx, nginx.default. nginx.default.svc, and nginx.default.svc.cluster-local IIRC. This also applies to your python code; it will use the same service naming rules as I list above. Typicall SERVICE-NAME.NAMESPACE is enough, although if the pod is in the same namespace, SERVICE-NAME will resolve when your python code calls the DNS library.