I have a pod running a Flask app in python, which is listening in port 8083. If I access the app from inside the pod, it works:
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
[...]
But when I look for the pod 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
And try to access it from outside the pod
curl http://10.1.45.187:8083
curl: (7) Failed to connect to 10.1.45.187 port 8083: Conexión rehusada
It can't connect.
I have done the same with other apps running in nodejs, and they work correctly. What can be happening here? How can I debug why it isn't connecting? Thanks in advance.
I'm leaving the yaml here:
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
Usually this is the case when the python app does only use the loopback interface to listen for connections. Make sure that the listening interface (host) is not 127.0.0.1 but 0.0.0.0
app.run(host='0.0.0.0', port=8080)