Items to Check to Prevent Timeout for Slow Responses in Kubernetes Ingress + Uwsgi Configuration

kubernetes
2022-08-19 10:51 (3 years ago)
Items to Check to Prevent Timeout for Slow Responses in Kubernetes Ingress + Uwsgi Configuration

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.

1. Ingress

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'

2. uwsgi.ini

[uwsgi]
...
socket-timeout = 600
http-timeout = 600
harakiri = 600

Measurement View

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))
Currently unrated
The author runs the application development company Cyberneura.
We look forward to discussing your development needs.

Categories

Archive