Kubernetes: Update all pods in parallel

Viewed 66

Is there any way to perform an update action on all pods simultaneously?

We have a process running in kubernetes as a stateful set where we want to update all the pods at the same time. We cannot seem to find a configuration for that. I am aware of rollingUpdate, which only updates one pod at a time.

This is what we have currently

  updateStrategy:
    rollingUpdate:
      partition: 2
    type: RollingUpdate

I also tried with maxUnavailable, but still did not work. Is there any other hack to get this done?

1 Answers

There is no native alternative for updating all pods simultaneously when using Statefulsets.

The closest thing to it is to use the Parallel Pod Management policy, but it only affects the behavior for scaling operations (including initial setup) and doesn't work for updates.


Although, the OpenKruise project has an extended component suite that enables Advanced StatefulSet to update workflow.

Here is a minimal working example that will upgrade all pods at once:

apiVersion: apps.kruise.io/v1beta1
kind: StatefulSet
metadata:
  name: sample
spec:
  replicas: 5
  serviceName: fake-service
  selector:
    matchLabels:
      app: sample
  template:
    metadata:
      labels:
        app: sample
    spec:
      readinessGates:
      - conditionType: InPlaceUpdateReady
      containers:
      - name: main
        image: nginx:alpine
  podManagementPolicy: Parallel
  updateStrategy:
    type: RollingUpdate
    rollingUpdate:
      maxUnavailable: 100%

Note this will certainly cause downtime, but you can adjust to something like maxUnavailable: 50% to make it more resilient.

Related