i have been setting up a K8s cluster and this is my config (below), and i have a problem with ingress returning 502 bad gateway.
I have everything green on my dashboard and i just cant figure out how the traffic is getting stuck in here.
All images (dockerfiles) work 100% locally.
I have looked through most of the similar questions here and i havent found the problem yet so thanks for your help in advance.
apiVersion: apps/v1
kind: Deployment
metadata:
name: moneyapi-deployment
labels:
app: moneyapi-deployment
spec:
replicas: 1
selector:
matchLabels:
app: moneyapi
template:
metadata:
labels:
app: moneyapi
spec:
containers:
- name: moneyapi
image: money/api:latest
ports:
- containerPort: 8080
imagePullSecrets:
- name: projesecret
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: moneyfrontend-deployment
labels:
app: moneyfrontend-deployment
spec:
replicas: 1
selector:
matchLabels:
app: moneyfrontend
template:
metadata:
labels:
app: moneyfrontend
spec:
containers:
- name: moneyfrontend
image: money/frontend:latest
ports:
- containerPort: 3000
imagePullSecrets:
- name: projesecret
---
apiVersion: v1
kind: Service
metadata:
name: moneyapiservice
spec:
selector:
app: moneyapi
ports:
- protocol: TCP
port: 8000
targetPort: 8080
---
apiVersion: v1
kind: Service
metadata:
name: moneyfrontendservice
spec:
selector:
app: moneyfrontend
ports:
- protocol: TCP
port: 3030
targetPort: 3000
---
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: moneyingress
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /$1
spec:
rules:
- http:
paths:
- path: /api
backend:
serviceName: moneyapiservice
servicePort: 8000
- path: /
backend:
serviceName: moneyfrontendservice
servicePort: 3030
Connection refused means the container is not listening on port 3000. Check the docker file of the image and maybe it's listening on some other port such as 80 or 8080. If that is the case then changing the targetPort of the service from 3000 to right port should make it work.