我有一个pod在python中运行一个Flask应用程序,它在8083端口侦听。如果我从吊舱内访问该应用程序,它就会工作:
kubectl exec gen-759dcfd789-hscbr -c gen-pod -- curl http://localhost:8083
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
[...]
但当我寻找吊舱IP
kubectl describe pod gen-759dcfd789-hscbr
Name: gen-759dcfd789-hscbr
Namespace: default
Priority: 0
Node: [...]
Start Time: Wed, 15 Apr 2020 19:18:12 +0200
Labels: app=gen
pod-template-hash=759dcfd789
Annotations: <none>
Status: Running
IP: 10.1.45.187
IPs:
IP: 10.1.45.187
Controlled By: ReplicaSet/gen-759dcfd789
并尝试从吊舱外访问它
curl http://10.1.45.187:8083
curl: (7) Failed to connect to 10.1.45.187 port 8083: Conexión rehusada
它无法连接。
我对在nodejs中运行的其他应用程序也做了同样的操作,它们工作正常。这里会发生什么?如何调试它未连接的原因?提前谢谢。
我要把yaml留在这里:
apiVersion: apps/v1
kind: Deployment
metadata:
name: gen
namespace: default
spec:
replicas: 1
selector:
matchLabels:
app: gen
template:
metadata:
labels:
app: gen
spec:
containers:
- name: gen-pod
image: roxax19/python3.7:0.1
command:
- bash
- "-c"
- python3.7 gen.py
volumeMounts:
- mountPath: /mount
name: test-volume
volumes:
- name: test-volume
hostPath:
# directory location on host
path: /home/manuel/tfg/mounts/gen
# this field is optional
type: Directory
通常情况下,python应用程序只使用环回接口来侦听连接。确保监听接口(主机(不是127.0.0.1而是0.0.0.0
app.run(host='0.0.0.0', port=8080)