1

I have made a nginx deployment which will be tagged by a ClusterIP service via a selector. Then I entered a new pod that is not related to that deployment nor service. And from within that pod I try to ping the i.p of the ClusterIP service hoping it would reach the nginx deploy, but it's not receiving the ping response.

The nginx deployment I made was with this manifest.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-nginx
spec:
  selector:
    matchLabels:
      run: my-nginx
  replicas: 1
  template:
    metadata:
      labels:
        run: my-nginx
    spec:
      containers:
      - name: my-nginx
        image: nginx
        ports:
        - containerPort: 80

Then, the service I created was with this manifest:

apiVersion: v1
kind: Service
metadata:
  name: basicping-service
  labels:
    run: my-nginx
spec:
  ports:
  - port: 80
    protocol: TCP
  selector:
    run: my-nginx

I made sure the service got created by running kubectl get svc and it did, the i.p is 10.98.91.185

And then I created a new pod completely unrelated to this deployment&Service.

kubectl run -it --rm --image=ubuntu bash

From within it, I pinged a sandbox server called pingtest.net just to see it was able to send requests and receive response. And it did

So finally, I tried pinging the basicping-service created previously by trying to ping the i.p of the service, I did this by running ping 10.98.91.185

And here is the problem. It does sends pings but doesn't receives the responses back, even after several minutes.

It was my understanding that the ping should have received a response. But is my understanding of services incorrect ? Or it should have worked but there is an error?

Just for more documentation, the my-nginx deployment is running, and the pod as well. And there seems to be nothing wrong with the nginx running in it. I checked this by running the kubectl describe of the deploy & pod, and also by checking the pod's logs, it's running nginx correctly apparently. Also, after running kubectl describe svc basicping-service it does shows the nginx pod's i.p address with port 80 as the endpoint

  • 2
    You should be able to ping a specific pod, but no a service. https://stackoverflow.com/questions/50852542/kubernetes-cannot-ping-another-service – Andromeda Apr 07 '23 at 20:02
  • 1
    ping(1) sends packets using the very-low-level ICMP protocol, but Nginx serves HTTP which uses the TCP protocol instead. Can you `curl` or `wget` the Pod via the Service? – David Maze Apr 08 '23 at 04:40
  • Yes I can crul and wget, I get that was the problem now. Thanks! – Eugenio.Gastelum96 Apr 08 '23 at 11:46

1 Answers1

1

ping doesn't work with a service's cluster IP, as it is a virtual IP. You should be able to ping a specific pod, but not a service.

ping sends packets using the very-low-level ICMP protocol, but Nginx serves HTTP which uses the TCP protocol instead.

Siegfred V.
  • 1,143
  • 3
  • 12