1
votes

I have a Kubernetes setup on Minikube with this configuration:

---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: myappdeployment
spec:
  replicas: 5
  selector:
    matchLabels:
      app: myapp
  template:
    metadata:
      labels:
        app: myapp
    spec:
      containers:
        - name: myapp
          image: custom-docker-image:latest
          ports:
            - containerPort: 3000

---
kind: Service
apiVersion: v1
metadata:
  name: example-service
spec:
  selector:
    app: myapp
  ports:
    - protocol: "TCP"
      # Port accessible inside cluster
      port: 3000
      # Port to forward to inside the pod
      targetPort: 3000
  type: NodePort

---
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: example-ingress
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /$1
spec:
  - http:
      paths:
      - path: /
        backend:
          serviceName: example-service
          servicePort: 3000

I took a look at the solution to this Stackoverflow post and it seems my configuration is.. fine?

What am I doing wrong to get 502 Bad Gateway when accessing http://192.xxx.xx.x, my Minikube address? The nginx-ingress-controller logs say:

...
Connection refused while connecting to upstream
...

Another odd piece of info, when I follow this guide to setting up the basic node service on Kubernetes, everything works and I see a "Hello world" page when I open up the Minikube add

1
Is your app definitely listening on port 3000? If you use kubectl port-forward to the pod, are you able to curl it ok?wobr
ah interesting, I ran this and it seems I get an error occurred forwarding 3000 -> 3000 - I looked at the logs for that individual pod and it seems I'm missing the MySQL setup, which stops the pod from starting, despite it being green in the Kubernetes dashboardSticky
thank you for this! learned a new trick to debug by port-forwarding just one single podSticky
Nice, glad to help!wobr
Please, consider posting an answer if the problem is solved. It would be more clear and helpful for the rest of the community.Wytrzymały Wiktor

1 Answers

2
votes

Steps taken: I ran

kubectl port-forward pods/myappdeployment-5dff57cfb4-6c6bd 3000:3000

Then I visited localhost:3000 and saw

This page isn’t working
localhost didn’t send any data.
ERR_EMPTY_RESPONSE

I figured the reason is more obvious in the logs so I ran

kubectl logs pods/myappdeployment-5dff57cfb4-6c6bd 

and got

Waiting for MySQL...
no destination
Waiting for MySQL...
no destination
Waiting for MySQL...
no destination
Waiting for MySQL...
no destination
...

Thus I reasoned that I was originally getting a 502 because all of the pods were not running due to no MySQL setup.