Simultaneous deploying of replicas

239 views Asked by At

With default settings, a deployment consisting of n replicas of a service will follow the below order during deploy:

Start pod 1 -> Wait for pod 1 to be ready
Once pod 1 is ready, start pod 2 -> Wait for pod 2 to be ready
...
Once pod n-1 is ready, start pod n -> Wait for pod n to be ready

In my application, it takes several minutes before the service can accept traffic (is ready). Hence I would like to configure my deployment to follow:
Start pod 1 -> Start pod 2 ... -> Start pod n
Once all pods are started, wait for pods 1 to n to become ready.

    ---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-webservice
spec:
  replicas: n
  selector:
    matchLabels:
      app.kubernetes.io/name: my-webservice
  template:
    metadata:
      labels:
        app: my-webservice
        app.kubernetes.io/name: my-webservice
    spec:
      securityContext:
        runAsNonRoot: true
      containers:
      - name: my-webservice
        image: "my.docker.repo/my-webservice:latest"
        ports:
        - containerPort: 5000
        readinessProbe:
          httpGet:
            path: /ready
            port: 5000
          initialDelaySeconds: 10
          periodSeconds: 10
          timeoutSeconds: 5
          failureThreshold: 360

How can I configure this?

2

There are 2 answers

1
pol92 On BEST ANSWER

You may try to add .spec.strategy.rollingUpdate.maxSurge field in your deployment.yml (Check here)

I think what you need is to set maxSurge: n

In your example:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-webservice
spec:
  replicas: n
  strategy:
    rollingUpdate:
      maxSurge: n
  selector:
    matchLabels:
      app.kubernetes.io/name: my-webservice
  template:
    metadata:
      labels:
        app: my-webservice
        app.kubernetes.io/name: my-webservice
    spec:
      securityContext:
        runAsNonRoot: true
      containers:
      - name: my-webservice
        image: "my.docker.repo/my-webservice:latest"
        ports:
        - containerPort: 5000
        readinessProbe:
          httpGet:
            path: /ready
            port: 5000
          initialDelaySeconds: 10
          periodSeconds: 10
          timeoutSeconds: 5
          failureThreshold: 360

Thus, when you apply an update, n new pods will be created simultaneously.

0
Kelson Martins On

One approach is to drop the readinessProbe and use only livenessProbe with the initialDelaySeconds that fits better your use-case.

If using readinessProbe, by design the deployment will move to the next replica only when the first is identified as ready.

So by using livenessProbe, all of them will start straightaway, but you can leverage the initialDelaySeconds to identify when to start checking if pod is alive.