I am attempting to have a kubernetes nginx deployment with zero downtime. Part of that process has been to initiate a rollingUpdate, which ensures that at least one pod is runni
I hate answering my own questions, but after noodling a bit this is what i have so far.
I created a bash script that is semi-blocking, called killer
:
#!/bin/bash
sleep 3
PID=$(cat /run/nginx.pid)
nginx -s quit
while [ -d /proc/$PID ]; do
sleep 0.1
done
I found that inside the nginx pod there is a file /run/nginx.pid
which has the PID of the master process. If you call nginx -s quit
and initiate a wait until the process disappears, you have essentially made the quit command "blocking".
Note that there is a sleep 3
before anything happens. This is due to a race condition where Kubernetes marks a pod as terminating, but takes a little time (< 1s) to remove this pod from the service that points traffic toward it.
I have mounted this script into my pod, and called it via the preStop
directive. It mostly works, but during testing there are still occasional blips where i get a curl error that the connection was "reset by peer." But this is a step in the right direction.