Kubernetes doesn't wait for all websocket connections to close before terminating during rolling update Kubernetes doesn't wait for all websocket connections to close before terminating during rolling update kubernetes kubernetes

Kubernetes doesn't wait for all websocket connections to close before terminating during rolling update


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.


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.