<p>I'm running uwsgi+flask application, 
The app is running as a k8s pod.</p>

<p>When i deploy a new pod (a new version), the existing pod get SIGTERM.</p>

<p>This causes the master to stop accepting new connection <strong>at the same moment</strong>, what causes issues as the LB still pass requests to the pod (for a few more seconds). </p>

<p>I would like the master to wait 30 sec BEFORE stop accepting new connections (When getting SIGTERM) but couldn't find a way, is it possible?</p>

<p>My uwsgi.ini file:
[uwsgi]</p>

<pre><code>;https://uwsgi-docs.readthedocs.io/en/latest/HTTP.html
http = :8080
wsgi-file = main.py
callable = wsgi_application
processes = 2
enable-threads = true
master = true
reload-mercy = 30
worker-reload-mercy = 30
log-5xx = true
log-4xx = true
disable-logging = true
stats = 127.0.0.1:1717
stats-http = true
single-interpreter= true
;https://github.com/containous/traefik/issues/615
http-keepalive=true
add-header = Connection: Keep-Alive
</code></pre>

<p>Seems like this is not possible to achieve using uwsgi:</p>

<p><a href="https://github.com/unbit/uwsgi/issues/1974" rel="noreferrer">https://github.com/unbit/uwsgi/issues/1974</a></p>

<p>The solution - (as mentioned on this kubernetes issue):</p>

<p><a href="https://github.com/kubernetes/contrib/issues/1140" rel="noreferrer">https://github.com/kubernetes/contrib/issues/1140</a></p>

<p>Is to use the prestop hook, quite ugly but will help to achieve zero downtime:</p>

<pre class="lang-yaml prettyprint-override"><code>apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: nginx
spec:
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx
        ports:
        - containerPort: 80
        lifecycle:
          preStop:
            exec:
              command: ["/bin/sleep","5"]
</code></pre>

<p>The template is taken from this answer: <a href="https://stackoverflow.com/a/39493421/3659858">https://stackoverflow.com/a/39493421/3659858</a></p>
