Search code examples
kubernetesgoogle-kubernetes-enginekubectlkubernetes-podkubernetes-deployment

Kubernetes Limit Deployment to one instance


I'm having a Kubernetes deployment configured in deployment.yaml which is just 1 replica. The replica is running a container which running a process and it's very important to ensure there's no moment in time when there are two instances of this process are running.

The deployment / re-deployment is something I don't have control on and happens with kubectl apply -f deployment.yaml whenever there's a change to the spec.

This is not great, because k8s brings down a deployment only after the new one is up and running.

If I had control over how it's deployed, I would have executed kubectl delete -f deployment.yaml and then kubectl apply -f deployment.yaml. However, I don't have control over it.

Question: how can I configure that in my deployment spec? i.e. to ensure there's no moment in time when there are two instances of the process running.

Thanks!


Solution

  • The default deployment strategy is rollingUpdate which brings your new pod up before the old pod goes down based on the values maxSurge and maxUnavailable.

    Instead use recreate strategy. It will bring down the old pod, then bring up the new pod. You can configure this in your deployment.yaml file