streetsoldier
streetsoldier

Reputation: 1319

how to stagger pod creation in k8s

I had a quick question about rolling deploys. I'm trying to make sure that the app pods creation is staggered. I looked at maxSurge and maxUnavailable which seems to be the only settings for controlling rolling deploys. Both these settings talk about pod creation in terms of old replicaset. I want to make sure that pod creation is staggered even when there is no deployment currently running.

example: If I set maxSurge to 1 and I have the replication set to 5 then in the presence of old deployment, the rolling update strategy will do the right thing and get one pod up at a time, but if there is no old deployment, all the 5 pods will come up together on a new deployment which is something I am trying to avoid.

Upvotes: 0

Views: 1425

Answers (2)

matthenry87
matthenry87

Reputation: 122

You could try leveraging a HorizontalPodAutoscaler with maybe a custom metric that could be set to whatever value will result in your desired number of replicas. Then just configure your HPA so it only scales up so many at a time.

Upvotes: 0

RAMNEEK GUPTA
RAMNEEK GUPTA

Reputation: 783

What you have explaied is the ecpected behaviour in case there are no existing deployments. So you want to do a ordered deployment - one pod after the other.

Try deploying the application as a statefulset. https://kubernetes.io/docs/concepts/workloads/controllers/statefulset/

Also note the differences b/w a deployment and a statefulset, for example no rollback in case of statefulset https://blog.thecodeteam.com/2017/08/16/technical-dive-statefulsets-deployments-kubernetes/

Upvotes: 1

Related Questions