skip to Main Content

I have a linux vm with k3s installed, and installed a Nginx-Ingress controller. I’m facing an issue while setting up the Nginx Ingress controller in my Kubernetes cluster. My goal is to setup https in the frontend, but I keep encountering a persistent 502 Bad Gateway error when accessing my application via the Ingress URL (app.192.168.[something].nip.io).

These are the details of the frontend service. (kubectl describe svc)

These are all the pods.

The results of (kubectl get svc -o wide)

The error logs of the Ingress-NginX shows:

connect() failed (111: Connection refused) while conencting to upstream, client: 192.168.223.229, server: app.192.168.[something].nip.io, request:
"GET / HTTP/ 2.0", upstream:  "http://10.43.141.56:3000/", host: "app.192.168.[something].nip.io"

The frontend runs, the pod is up, I’m not sure where to go from here.

The Ingress resource:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: ingress
  annotations:
    nginx.ingress.kubernetes.io/service-upstream: "true"
spec:
  ingressClassName: nginx
  tls:
  - secretName: dailygrind-tls
    hosts:
    - app.192.168.[something].nip.io
  rules:
  - host: app.192.168.[something].nip.io
    http:
      paths:
      - pathType: Prefix
        path: "/"
        backend:
          service:
            name: frontend
            port:
              number: 3000

2

Answers


  1. Please note that service frontend located in default namespace is LoadBalancer type and I think it should be ClusterIP since you don’t want to publicly expose your service and then connect to it via ingress.

    Login or Signup to reply.
  2. The issue is related to the communication between the Nginx Ingress Controller and the backend service (frontend) running on port 3000. The error message connect() failed (111: Connection refused) while connecting to upstream indicates that Nginx cannot establish a connection to the backend service.

    Here are some steps to troubleshoot the issue:

    Verify Backend Service: Make sure that the frontend service is running and accessible within the cluster. You can do this by checking the status of the frontend pods (kubectl get pods) and ensuring that they are in a Running state.
    Check Service IP and Port: Confirm that the IP address and port of the frontend service match the values specified in the Ingress resource (kubectl describe svc frontend). Ensure that the service is listening on port 3000.
    Verify Ingress Configuration: Double-check the Ingress configuration to ensure that it correctly specifies the backend service (frontend) and port 3000. Pay attention to any typos or misconfigurations in the path and backend sections.
    Check Network Policies: If you have Network Policies enabled in your cluster, ensure that there are no policies blocking traffic between the Nginx Ingress Controller and the backend service.
    Inspect Nginx Ingress Logs: Look for any errors or warnings in the logs of the Nginx Ingress Controller pods (kubectl logs ). This may provide more insights into why the connection to the upstream service is being refused.
    Test Connectivity: Try to manually connect to the backend service from within the cluster using tools like curl or telnet to verify that it is reachable (curl http://frontend:3000). If it’s not reachable, there may be issues with the service itself or its network configuration.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search