I have some problem with my Kubernetes ingress for only this service that always returns 502.
I have tested the service and it’s working fine, but when I expose it with ingress it doesn’t work.
I use EKS and Nginx ingress controller
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
namespace: develop
name: chatbot-ingress
annotations:
kubernetes.io/ingress.class: "nginx"
spec:
rules:
- http:
paths:
- backend:
service:
name: chatbot
port:
number: 7070
pathType: Prefix
path: /
host: api.example.com
---
apiVersion: v1
kind: Service
metadata:
name: chatbot
namespace: develop
spec:
selector:
app: chatbot
ports:
- port: 7070
targetPort: 7070
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: chatbot
namespace: develop
spec:
selector:
matchLabels:
app: chatbot
template:
metadata:
labels:
app: chatbot
spec:
containers:
- name: chatbot
image: chatbot
imagePullPolicy: Always
envFrom:
- secretRef:
name: chatbot-secret
ports:
- containerPort: 7070
Ingress log
2022/06/16 13:51:20 [error] 2069#2069: *9278411 connect() failed (111: Connection refused) while connecting to upstream, client: 192.168.49.139, server: api.example.com, request: "GET / HTTP/2.0", upstream: "http://192.168.8.148:7070/", host: "api.example.com"
2022/06/16 13:51:20 [error] 2069#2069: *9278411 connect() failed (111: Connection refused) while connecting to upstream, client: 192.168.49.139, server: api.example.com, request: "GET / HTTP/2.0", upstream: "http://192.168.8.148:7070/", host: "api.example.com"
2
Answers
It turned out that the image that I run expose on localhost:7070 instead of 0.0.0.0:7070. However, I still don't know why my service was able to connect to the pod and I could test it by port forwarding but my ingress wasn't able to connect with that working service.
Should that host be updated from api.example.com to the relevant endpoint of the service to connect to?
Something that might help is using a service like Lumigo to do some tracing (they have a free tier)