我在两个不同的虚拟机上部署了两个 pod。(主节点和节点)。
Dockerfile 服务器端
EXPOSE 8080
CMD ["python", "model.py"]
服务器端python代码
sock = socket()
sock.bind(('',8080))
客户端python代码
sock= socket()
sock.connect(('192.168.56.105', 8080))
Pod 部署文件服务器
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 部署文件服务器
apiVersion: v1
kind: Pod
metadata:
name: client
labels:
app: client
spec:
containers:
- name: tensor
image: tensor:latest
暴露节点端口
kubectl expose pod server --type=NodePort
kubectl expose pod client --port 27017 --type=NodePort
kubectl 获取服务
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
然后我为服务器和客户端运行以下命令,它说它正在等待客户端连接并且它没有连接。
kubectl exec -it server -- /bin/sh
但是,当我键入以下命令时,它已连接,但我收到对等方重置的错误连接。
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
错误
Traceback (most recent call last):File "model.py", line 51, in <module> client.sendall(data)
ConnectionResetError: [Errno 104] Connection reset by peer
非常感谢您帮助我,非常感谢您的帮助。我被卡住了,我尝试过端口转发,但它不起作用。