I am trying to achieve 0 downtime during rolling update with EKS (AWS K8s service).
I have one WebSocket server and I want to ensure during the rolling update of this server, existing connections will be kept until the WebSockets are closed after the work is done.
I thought K8s rolling update feature would help me with this but it did not. I tried and it simply killed the pod while there were still connections to the WebSocket.
If I understand the document correctly, then the pod termination goes like this:
grace-period
(default to 30s)If my above understanding is correct, clearly there is no way to tell K8s to:
Question: Is there any ways at all to make sure K8s:
grace-period
If anyone can assist me that would be greatly appreciated.
For mission critical application, go for customised blue-green deployments.
First deploy new version deployment with new selector and when all POD replicas are UP and ready to serve traffic, switch the service selector to point to new version deployment.
After this send the kill switch to older version which gracefully handles and disconnect all clients. So all new reconnections are forwarded to new version which is already set to serve traffic.
You can use the lifecycle hook
in kubernetes pod lifecycle which have a preStop hook
. This hook will run just before the termination of your pod.
lifecycle:
postStart:
exec:
command: ["/bin/sh", "-c", "echo Hello from the postStart handler > /usr/share/message"]
preStop:
exec:
command: ["/bin/sh","-c","nginx -s quit; while killall -0 nginx; do sleep 1; done"]
You can have your script to kill all the connections and wait for the connection to terminate and then only the pod will terminate.