With Kubernetes Is there a way to wait for a pod to finish its ongoing tasks before updating it?

Viewed 1949

I'm managing a application inside kubernetes, I have a front end (nginx, flask) and a backend (celery) Long running tasks are sent to the backend using a middle-ware (rabbitmq)

My issue here is that i can receive long running tasks at anytime, and i don't want it to disturb my plan of upgrading the version of my application.

I'm using the command kubectl apply -f $MY_FILE to deploy/update my application. But if i do it when a celery po is busy, the pod will be terminated, and i'll be losing the task.

I tried using the readiness probe, but the pods are still being terminated. My question is, is there a way for kube to target only 'free' pods, and wait for the busy on to finish ?

Thank you

2 Answers

One way is to create another deployment with the new image, expose it as a service. Pass on any new requests ONLY to this new deployment/service.

Meanwhile, the old deployment/service can still continue processing the existing requests and not take any new ones. Once all the requests are processed the old deployment/service can be deleted.

The only problem with this approach, roughly double the resources are required for some duration as old/new deployment/service run in parallel.

Something like a A/B testing. FYI ... Istio makes is easy with traffic management.

Related