Issue in communicating two pods with each other deployed on two VMs

10/27/2020

I have deployed two pods on two different Virtual machines. (master and node).

Dockerfile server-side

EXPOSE 8080
CMD ["python", "model.py"]

Server-side python code

sock = socket()
sock.bind(('',8080))

Client-side python code

sock= socket()
sock.connect(('192.168.56.105', 8080))

Pod deployment file server

 apiVersion: v1
 kind: Pod
 metadata:
 name: server
 labels:
    app: server
 spec:
    containers:
    - name: tensor-keras
      image: tensor-keras:latest
      imagePullPolicy: Never
    ports:
     - containerPort: 8080

Pod deployment file server

apiVersion: v1
kind: Pod
metadata:
  name: client
  labels:
    app: client
 spec:
   containers:
    - name: tensor
      image: tensor:latest
       

Exposing node port

 kubectl expose pod server --type=NodePort
 kubectl expose pod client --port 27017 --type=NodePort

kubectl get services

NAME           TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)           AGE
client         NodePort    10.105.180.221   <none>        27017:31161/TCP   11s
server         NodePort    10.106.22.209    <none>        8080:32284/TCP    35s
kubernetes     ClusterIP   10.96.0.1        <none>        443/TCP           28h

I then run the below command for the server and client, it says its waiting for the client to connect and it doesn't gets connected.

 kubectl exec -it server  -- /bin/sh

But the moment I type the below command Its get connected but I receive an error connection reset by peer.

    curl -v localhost:32284
   * Rebuilt URL to: localhost:32284/
   * Connected to localhost (127.0.0.1) port 32284 (#0)
   > GET / HTTP/1.1
   > Host: localhost:32284
   > User-Agent: curl/7.58.0
   > Accept: */*
    predictions_result.npy
    141295744
    Warning: <FILE>" to save to a file.
    * Failed writing body (0 != 13880)
    * stopped the pause stream!
    * Closing connection 0

Error

     Traceback (most recent call last):File "model.py", line 51, in <module> client.sendall(data)
     ConnectionResetError: [Errno 104] Connection reset by peer

Thank you very much for helping me with this, help is highly appreciated. I am stuck I have tried port forwarding but it's not working.

-- abaair davis
kubernetes
kubernetes-networking
kubernetes-pod
python

0 Answers