In Kubernetes Deployment, how not to start all the pods at once

1/28/2022

I am using Kubernetes deployment. I wish to start the pods one by one. Not all at once. Is there any way. I do not want to use statefulSet.

kind: Deployment
metadata:
  name: my-deployment
  labels:
    app: my-app
spec:
  replicas: 3
  selector:
    matchLabels:
      app: my-app
  template:
    metadata:
      labels:
        app: my-app
    spec:
      containers:
      - name: my-app
        image: my-container-image
        ports:
        - name: https
          containerPort: 8443
        volumeMounts:
            - mountPath: /tmp
              name: app-vol
        restartPolicy: Always
      imagePullSecrets:
        - name: regcred
      volumes:
        - name: app-vol
          persistentVolumeClaim:
            claimName: app-vol
-- Hitesh Bajaj
kubernetes

1 Answer

1/31/2022

I wish to start the pods one by one. Not all at once. Is there any way. I do not want to use statefulSet.

Unfortunately you are trying to accomplish something with Deployment that is achievable with Statefulset. Is it possible to achieve the desired effect with deployment? A similar one can be obtained, but it will require creating a custom script and it will be a non-standard solution.

However, this will not be a recommended solution. Statefulset works well for feed control during starts, and you shouldn't use anything else here.

To sum up: you should change the assumptions a bit and accept the statefulset, thanks to which you will achieve the result you want, or you should not control the order in which the pods are run.

As rohatgisanat mentioned in the comment:

Deployments do not guarantee ordered starts. StatefulSets are the way to achieve what you require.

-- Mikołaj Głodziak
Source: StackOverflow