So, I am trying to deploy a personal website app and expose it to a local domain (for now) but I am always getting a 502 Bad Gateway from my nginx-ingress-controller.
So, for such task I have built 3 files: deployment.yaml
, service.yaml
and ingress.yaml
:
apiVersion: apps/v1
kind: Deployment
metadata:
name: website-deployment
labels:
app: website
spec:
replicas: 1
selector:
matchLabels:
app: website
template:
metadata:
labels:
app: website
spec:
containers:
- name: website
image: jotinha2014/private
ports:
- containerPort: 55004
apiVersion: v1
kind: Service
metadata:
name: website-service
spec:
selector:
app: website
ports:
- protocol: TCP
port: 80
targetPort: 55004
type: ClusterIP
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: website-ingress
namespace: default
annotations:
nginx.ingress.kubernetes.io/service-upstream: "true"
nginx.ingress.kubernetes.io/rewrite-target: /
spec:
rules:
- host: rabanadas.eu
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: website-service
port:
number: 80
Here are some logs from my nginx-ingress-controller:
2021/01/03 01:13:31 [error] 1371#1371: *34677 connect() failed (111: Connection refused) while connecting to upstream, client: 192.168.64.1, server: rabanadas.eu, request: "GET / HTTP/1.1", upstream: "http://10.106.8.10:80/", host: "rabanadas.eu"
2021/01/03 01:13:31 [error] 1371#1371: *34677 connect() failed (111: Connection refused) while connecting to upstream, client: 192.168.64.1, server: rabanadas.eu, request: "GET / HTTP/1.1", upstream: "http://10.106.8.10:80/", host: "rabanadas.eu"
2021/01/03 01:13:31 [error] 1371#1371: *34677 connect() failed (111: Connection refused) while connecting to upstream, client: 192.168.64.1, server: rabanadas.eu, request: "GET / HTTP/1.1", upstream: "http://10.106.8.10:80/", host: "rabanadas.eu"
192.168.64.1 - - [03/Jan/2021:01:13:31 +0000] "GET / HTTP/1.1" 502 552 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36" 474 0.000 [default-website-service-80] [] 10.106.8.10:80, 10.106.8.10:80, 10.106.8.10:80 0, 0, 0 0.000, 0.000, 0.000 502, 502, 502 dff7944bbbc17be35584fee465d047d2
W0103 01:15:52.298006 8 warnings.go:67] networking.k8s.io/v1beta1 Ingress is deprecated in v1.19+, unavailable in v1.22+; use networking.k8s.io/v1 Ingress
Right now I am using minikube and, as such, my nginx-ingress-controller was configure just by adding it as addon. I suspect that the problem is with my ingress configuration because I've already port-forwarded the pod deployed and the website is showing as it is supposed on the right port.
As requested, here are my website pod details:
Name: website-deployment-69f57fc45-l4th9
Namespace: default
Priority: 0
Node: minikube/192.168.64.5
Start Time: Sun, 03 Jan 2021 00:53:16 +0000
Labels: app=website
pod-template-hash=69f57fc45
Annotations: <none>
Status: Running
IP: 172.17.0.2
IPs:
IP: 172.17.0.2
Controlled By: ReplicaSet/website-deployment-69f57fc45
Containers:
website:
Container ID: docker://eae48617da80f3ac4832695535432581746d925fc497066a5fd8a707b3020a88
Image: jotinha2014/private
Image ID: docker-pullable://jotinha2014/private@sha256:0a9573429315745eae0a33339021c82db2e92e0ba35ca652aa20482af31f1219
Port: 55004/TCP
Host Port: 0/TCP
State: Running
Started: Sun, 03 Jan 2021 00:53:18 +0000
Ready: True
Restart Count: 0
Environment: <none>
Mounts:
/var/run/secrets/kubernetes.io/serviceaccount from default-token-j8pzx (ro)
Conditions:
Type Status
Initialized True
Ready True
ContainersReady True
PodScheduled True
Volumes:
default-token-j8pzx:
Type: Secret (a volume populated by a Secret)
SecretName: default-token-j8pzx
Optional: false
QoS Class: BestEffort
Node-Selectors: <none>
Tolerations: node.kubernetes.io/not-ready:NoExecute op=Exists for 300s
node.kubernetes.io/unreachable:NoExecute op=Exists for 300s
Events: <none>
Thanks in advance fo any help.
port-forward
to 55004 works but the Ingress does not, it's probably that your container is listening on 127.0.0.1 and not 0.0.0.0 – mdaniel55004
. Did you changenginx:alpine
to use this port, or should the targetPort in your service be80
? – Christian Fosli