Connect between the pods in the same namespace

12/13/2020

I need to connect between pod-1 and pod-2 in the same namespace. I want to test mutlicast using netcat.

I tried to listen on one pod and connect to that from the other pod using the pod-1 IP but that doesn't work. I even tried tomcat7.test-web-dev and that doesn't work either. Ping doesn't respond either.

apiVersion: v1
kind: Service
metadata:
  name: tomcat7
  namespace: test-web-dev
spec:
  selector:
    app: tomcat7 # Metadata label of the deployemnt pod template or pod metadata label
  ports:
    - name: port-1234 
      protocol: TCP
      port: 1234
      targetPort: 1234
    - name: port-1234 
      protocol: UDP
      port: 1234
      targetPort: 1234
-- John Doe
kubernetes

2 Answers

12/18/2020

<service-name>.<namespace>.svc.cluster.local or <service-name>.<namespace> works as well.

-- John Doe
Source: StackOverflow

12/13/2020

try connecting to:

<clusterip>.<namespace>.pod.cluster.local

or

<clusterip>.<namespace>.svc.cluster.local

but yes, in general, it is a pain to setup these things depending on your k8s deployment.

You can also enter the client pod using kubectl and try pinging the server one on different addresses until success.

kubectl exec --stdin --tty <client-pod-name> -- /bin/bash
-- Vasil Yordanov
Source: StackOverflow