Kubernetes deployment with Recreate strategy and maxSurge?

4/27/2020

Summary

Can I give a deployment the rollout strategy Recreate and also set a fixed maxSurge for the deployment?

More details

I am developing an application that runs in Kubernetes. The backend will have multiple replicas, and runs EF Core with database migrations. I understand there are several ways to solve this; here's my idea at the moment.

On a new release, I would like all replicas to be stopped. Then a single replica at a time should start, and for each replica there should be an init container that runs the migrations (if needed).

This seems to be possible, using the following two configuration values:

  • .spec.strategy.type==Recreate and
  • .spec.strategy.rollingUpdate.maxSurge==1

Is it possible to use these two together? If not, is there any way to control how many replicas a controller will start at once with the Recreate strategy?

"No! You should do this in a completely different way!"

Feel free to suggest other methods as well, if you think I am coming at this from the completely wrong angle.

-- MW.
kubernetes
kubernetes-deployment

1 Answer

4/27/2020

Statefulset might help you in this case.

StatefulSets are valuable for applications that require one or more of the following.
  • Stable, unique network identifiers.
  • Stable, persistent storage.
  • Ordered, graceful deployment and scaling.
  • Ordered, automated rolling updates.
-- hoque
Source: StackOverflow