When using an Nginx Ingress Controller in Kubernetes and having an application server in the Pod that uses Uwsgi, here are some points to check to prevent services with slow response times from timing out.
If you don't extend these settings, you may encounter 502 or 504 errors.
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: my-app
namespace: my-namespace
annotations:
nginx.ingress.kubernetes.io/proxy-connect-timeout: '900'
nginx.ingress.kubernetes.io/proxy-send-timeout: '900'
nginx.ingress.kubernetes.io/proxy-read-timeout: '900'
[uwsgi]
...
socket-timeout = 600
http-timeout = 600
harakiri = 600
import time
from django import http
from django.views import View
class DevSleepView(View):
"""
A view that sleeps for a long time. Used to check for timeouts
/dev/sleep/?seconds=60
"""
def get(self, request, *args, **kwargs):
sleep_time = int(request.GET.get('seconds', 30))
start = timezone.now()
time.sleep(sleep_time)
end = timezone.now()
return http.HttpResponse('{} - {}, Slept {}seconds.'.format(
start.strftime('%Y-%m-%d %H:%M:%S'),
end.strftime('%H:%M:%S'),
sleep_time))
Comments