Search code examples
kuberneteslinodekubernetes-statefulset

Setting podManagementPolicy for a StatefulSet


I am using a StatefulSet to deploy my application and I have 10 replicas. Because each pod waits for the previous pod to be ready, it takes a long time to spin up my cluster. I found the podManagementPolicy option on the Kubernetes documentation. I want to set podManagementPolicy to Parallel so my pods don't wait for each other (which I don't need) and my build time is shorter.

However, I am getting the following error when I try to set podManagementPolicy to Parallel:

The StatefulSet "xxx" is invalid: spec: Forbidden: updates to statefulset spec for fields other than 'replicas', 'template', 'updateStrategy', 'persistentVolumeClaimRetentionPolicy' and 'minReadySeconds' are forbidden

Here is the yaml file for my StatefulSet:

apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: xxx
spec:
  podManagementPolicy: Parallel
  selector:
    matchLabels:
      app: xxx
  serviceName: "xxx"
  replicas: 10
  minReadySeconds: 0
  template:
    metadata:
      labels:
        app: xxx
    spec:
      containers:
        - name: xxx
          image: xxx.com/xxx:latest
          imagePullPolicy: Always
          ports:
            - containerPort: 8000
      imagePullSecrets:
        - name: dockerregistrykey

I am using an Linode LKE cluster and the Kubernetes version is 1.25.


Solution

  • Looks like you are on K8s version 1.24 or above as mentioned in error you can only update a few fields in statefulset unlike Deployment or POD.

    So you have to delete and re-apply the new changes is the only solution.

    You can also create the new stateful set with a different name and keep the label same as the existing running one.

    Once one stateful set is up & running you can remove the older one and service will forward the traffic to new running replicas, guessing there won't be any issues with data as you mentioned about it being fine to run parallel.

    In case you have a requirement to use existing PVC to store the data, deleting the statefulset is only solution i am seeing.