Reputation: 27
I have a Spring Boot application running in a Docker container managed by Kubernetes whose job is to pull data from a queue, process it, and write back to a queue. Initially, the Deployment for this application is created with 1 replica. However, at some point I need to scale that Deployment up in order to process messages from the queue faster. Ideally, I'd like to have that existing 1 replica start processing messages, and then the new replicas can come up and help out.
The problem I've discovered is that when scaling the Deployment programmatically, the existing 1 replica is destroyed, and this typically is occurring in the middle of it processing some data, resulting in the output of that processing being lost.
Example of what I'd like to see happen:
Is this at all possible? Thanks!
Upvotes: 0
Views: 1250
Reputation: 27
As David Maze suggested, I was not only patching the number of replicas
but also patching an environment variable in the template
, causing the replica to be recreated in order to pick that new variable up.
Fritz's answer is also a great overall suggestion for a graceful shutdown.
Upvotes: 1
Reputation: 11930
Normally, Kubernetes scales up without restarting the existing Pods, so kind of unusual that this does not happen in your case.
That aside though, none of your Pods should shut down in a way that results in loss of messages. This suggests that you are missing code for graceful shutdown.
With Spring Boot and K8s you will have to do two things:
Upvotes: 2