Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ingress gives 502 error

Tags:

If I run through the http load balancer example it works fine in my google container engine project. When I run "kubectl describe ing" the backend is "HEALTHY". If I then change the svc out to one that points to my app as shown here:

apiVersion: v1
kind: Service
metadata:
  name: app
  labels:
    name: app
spec:
  ports:
  - port: 8000
    name: http
    targetPort: 8000
  selector:
    name: app
  type: NodePort

The app I'm running is django behind gunicorn and works just find if I make that a load balancer instead of a NodePort.

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: main-ingress
spec:
  backend:
    serviceName: app
    servicePort: 8000

Now when I run "kubectl describe ing" the backend is listed as "UNHEALTHY" and all requests to the ingress IP give a 502.

  1. Is the 502 a symptom of the bad health check?
  2. What do I have to do to make the health check pass? I'm pretty sure the container running my app is actually healthy. I never set up a health check so I'm assuming I have to configure something that is not configured, but my googling hasn't gotten me anywhere.
like image 660
Ian Avatar asked Feb 07 '17 23:02

Ian


People also ask

How do you debug a 502 on Kubernetes?

Check if the Pod and Containers is Running If the pod or one of its containers did not start, this could result in a 502 error to clients accessing an application running in the pod. If the entire pod or the required containers are not running—restart the pod or force Kubernetes to reschedule it.

Why do I keep getting a 502 error?

A 502 bad gateway message indicates that one server got an invalid response from another. In essence, you've connected with some kind of interim device (like an edge server) that should fetch all of the bits you need to load the page. Something about that process went wrong, and the message indicates the problem.


1 Answers

After a lot of digging I found the answer: According to the requirements here: https://github.com/kubernetes/kubernetes/tree/master/cluster/addons/cluster-loadbalancing/glbc#prerequisites the application must return a 200 status code at '/'. Because my application was returning a 302 (redirect to login), the health check was failing. When the health check fails, the ingress resource returns 502.

like image 183
Ian Avatar answered Sep 26 '22 22:09

Ian