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

kubernetes
2022-08-19 19:51 (2 years ago) ytyng

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

Comments

Archive

2024
2023
2022
2021
2020
2019
2018
2017
2016
2015
2014
2013
2012
2011