<p>I am using the below command to restart Pods in a statefulset</p>
<pre class="lang-bash prettyprint-override"><code>kubectl rollout restart statefulset ts
</code></pre>
<p>If I have to introduce a delay between pod rotation, is there an argument or any other method to achieve it? I am using a sidecar that updates the Pod IP address to a configuration file, if the Pod restarts before the IP address is updated in the config file, the service is not healthy. Looking for a way to introduce a delay between pod restarts/pod rotations.</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: typesense
  namespace: typesense
  labels:
    service: typesense
    app: typesense
spec:
  serviceName: ts
  podManagementPolicy: Parallel
  replicas: 3
  selector:
    matchLabels:
      service: typesense
      app: typesense
  template:
    metadata:
      labels:
        service: typesense
        app: typesense
    spec:
      serviceAccountName: typesense-service-account
      securityContext:
        fsGroup: 2000
        runAsUser: 10000
        runAsGroup: 3000
        runAsNonRoot: true
      terminationGracePeriodSeconds: 300
      containers:
        - name: typesense
          envFrom:
            # - configMapRef: 
            #     name: typesense-config
            - secretRef:
                name: typesense-secret
          image: typesense/typesense:0.23.0.rc43
          command:
            - &quot;/opt/typesense-server&quot;
            - &quot;-d&quot;
            - &quot;/usr/share/typesense/data&quot;
            - &quot;--api-port&quot;
            - &quot;8108&quot;
            - &quot;--peering-port&quot;
            - &quot;8107&quot;
            - &quot;--nodes&quot;
            - &quot;/usr/share/typesense/nodes&quot;
          ports:
            - containerPort: 8108
              name: http
          resources:
            requests:
              memory: 100Mi
              cpu: &quot;100m&quot;
            limits:
              memory: 1Gi
              cpu: &quot;1000m&quot;
          volumeMounts:
            - name: nodeslist
              mountPath: /usr/share/typesense
            - name: data
              mountPath: /usr/share/typesense/data
        - name: typesense-node-resolver
          image: alasano/typesense-node-resolver
          command:
            - &quot;/opt/tsns&quot;
            - &quot;-namespace=typesense&quot;
          volumeMounts:
          - name: nodeslist
            mountPath: /usr/share/typesense
      volumes:
        - name: nodeslist
          emptyDir: {}
  volumeClaimTemplates:
    - metadata:
        name: data
      spec:
        accessModes:
          - ReadWriteOnce
        storageClassName: nfs
        resources:
          requests:
            storage: 1Gi
</code></pre>
<p>You can find the full manifest <a href="https://github.com/ivishalgandhi/learn/blob/main/k8s/typesense/ts.yaml" rel="nofollow noreferrer">here</a>.</p>

Vishal
<p>Maybe using <a href="https://kubernetes.io/docs/concepts/workloads/pods/init-containers/" rel="nofollow noreferrer">init container</a> ?</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: typesense
  namespace: typesense
  labels:
    service: typesense
    app: typesense
spec:
  serviceName: ts
  podManagementPolicy: Parallel
  replicas: 3
  selector:
    matchLabels:
      service: typesense
      app: typesense
  template:
    metadata:
      labels:
        service: typesense
        app: typesense
    spec:
      serviceAccountName: typesense-service-account
      securityContext:
        fsGroup: 2000
        runAsUser: 10000
        runAsGroup: 3000
        runAsNonRoot: true
      terminationGracePeriodSeconds: 300
      initContainers:
        - name: init-myservice
          image: busybox:1.34.1
          command: [
              &quot;echo&quot;,
              &quot;ip&quot;,
              &quot;to&quot;,
              &quot;config&quot;,
              &quot;file&quot;,,
            ]
      containers:
        - name: typesense
          envFrom:
            # - configMapRef: 
            #     name: typesense-config
            - secretRef:
                name: typesense-secret
          image: typesense/typesense:0.23.0.rc43
          command:
            - &quot;/opt/typesense-server&quot;
            - &quot;-d&quot;
            - &quot;/usr/share/typesense/data&quot;
            - &quot;--api-port&quot;
            - &quot;8108&quot;
            - &quot;--peering-port&quot;
            - &quot;8107&quot;
            - &quot;--nodes&quot;
            - &quot;/usr/share/typesense/nodes&quot;
          ports:
            - containerPort: 8108
              name: http
          resources:
            requests:
              memory: 100Mi
              cpu: &quot;100m&quot;
            limits:
              memory: 1Gi
              cpu: &quot;1000m&quot;
          volumeMounts:
            - name: nodeslist
              mountPath: /usr/share/typesense
            - name: data
              mountPath: /usr/share/typesense/data
        - name: typesense-node-resolver
          image: alasano/typesense-node-resolver
          command:
            - &quot;/opt/tsns&quot;
            - &quot;-namespace=typesense&quot;
          volumeMounts:
          - name: nodeslist
            mountPath: /usr/share/typesense
      volumes:
        - name: nodeslist
          emptyDir: {}
  volumeClaimTemplates:
    - metadata:
        name: data
      spec:
        accessModes:
          - ReadWriteOnce
        storageClassName: nfs
        resources:
          requests:
            storage: 1Gi
</code></pre>
