<p>I am using Kubernetes and Google Cloud to host my web application
and was looking for a way to increase the time for waiting for the server response before returning the error
<code>Internal server error Sorry, there seems to be an error. Please try again soon.</code>
I tried to search for the Kubernetes objects but no result
thank you</p>

ladhari
<p>If I understand correctly, you have a Django application hosted on a Kubernetes cluster, which is managed on Google Cloud.</p>
<p>There are still missing pieces, though:</p>
<ul>
<li>the <a href="https://kubernetes.io/docs/concepts/services-networking/ingress-controllers/" rel="nofollow noreferrer">Kubernetes Ingress Controller</a> you are using, I will assume <a href="https://github.com/kubernetes/ingress-nginx" rel="nofollow noreferrer">NGINX</a></li>
<li>the <a href="https://wsgi.readthedocs.io/en/latest/what.html" rel="nofollow noreferrer">Web Server Gateway Interface (WSGI)</a> used by your <a href="https://docs.djangoproject.com/en/4.2/howto/deployment/wsgi/" rel="nofollow noreferrer">Django application</a>. I will assume <a href="https://gunicorn.org/" rel="nofollow noreferrer">Gunicorn</a>.</li>
</ul>
<p>That would be:</p>
<pre><code>+----------------------+
|   Google Cloud       |
|   Load Balancer      |
+----------------------+
           |
           v
+-----------------------+
|   Kubernetes Cluster  |
|   NGINX Ingress       |
|   Controller          |
+-----------------------+
           |
           v
+----------------------------+
|     Django Application     |
|   (served via Gunicorn)    |
+----------------------------+
</code></pre>
<ul>
<li><p><strong>Google Cloud Load Balancer</strong>: responsible for distributing incoming network traffic across several servers to ensure no single server becomes overwhelmed with too much traffic. It is the entry point for HTTP/S requests.</p>
</li>
<li><p><strong>Kubernetes NGINX Ingress Controller</strong>: manages external access to the services in the cluster, typically HTTP. It can provide load balancing, SSL termination, and name-based virtual hosting.</p>
</li>
<li><p><strong>Django Application (served via Gunicorn)</strong>: That is where the web application lives. Gunicorn acts as a WSGI HTTP Server for Python web applications, serving the Django application to handle incoming HTTP requests.</p>
</li>
</ul>
<p>Then you can identify the settings impacting timeout, at each level.</p>
<ul>
<li><p><strong>Django Settings</strong>: There is no setting directly affecting the waiting time for a response from the server before returning an error. You might want to look into custom middleware that can handle timeouts in a more graceful manner.</p>
<p>Note that an &quot;<a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/500" rel="nofollow noreferrer">500 Internal server error</a>&quot; can originate from the Django application itself (e.g., unhandled exceptions, misconfigurations, bugs in the code, etc.) or from other elements in the infrastructure, such as the database, cache, or other backend services that the Django application depends on.<br />
Make sure <a href="https://docs.djangoproject.com/en/4.2/topics/logging/" rel="nofollow noreferrer">Django's logging</a> is properly configured to capture errors and exceptions (see <a href="https://docs.djangoproject.com/en/4.2/topics/logging/#examples" rel="nofollow noreferrer"><code>settings.py</code></a>).<br />
Check the logs with <a href="https://cloud.google.com/logging" rel="nofollow noreferrer">Cloud Logging</a> or with a <a href="https://cloud.google.com/code/docs/shell/view-logs" rel="nofollow noreferrer"><code>kubectl logs &lt;pod-name&gt;</code> from the Cloud shell</a>.</p>
</li>
<li><p><strong>Gunicorn Settings</strong>: you can increase the timeout setting by modifying the <a href="https://docs.gunicorn.org/en/stable/settings.html#timeout" rel="nofollow noreferrer"><code>--timeout</code> flag</a> when starting Gunicorn (<code>gunicorn --timeout 120 myproject.wsgi:application</code>). That would set the timeout to 120 seconds.</p>
</li>
<li><p><strong>Kubernetes Ingress Settings</strong>: if you are using the NGINX Ingress controller, you can set the <a href="https://github.com/kubernetes/ingress-nginx/blob/main/docs/user-guide/nginx-configuration/annotations.md#custom-timeouts" rel="nofollow noreferrer"><code>nginx.ingress.kubernetes.io/proxy-read-timeout</code> and <code>nginx.ingress.kubernetes.io/proxy-send-timeout</code> annotations</a> on your Ingress object.</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  annotations:
    nginx.ingress.kubernetes.io/proxy-read-timeout: &quot;120&quot;
    nginx.ingress.kubernetes.io/proxy-send-timeout: &quot;120&quot;
...
</code></pre>
</li>
</ul>
<ol start="4">
<li><strong>Google Cloud Load Balancer Settings</strong>:
<ul>
<li>On Google Cloud, if you are using a load balancer in front of your Kubernetes cluster, you might also need to configure the timeout settings on the load balancer.</li>
</ul>
</li>
</ol>
<p>But again, a &quot;500 Internal Server Error&quot; might not be &quot;resolved&quot; by adding more time: logs are crucial to understand what is going on.</p>
