<p>According to <a href="https://kubernetes.io/docs/tutorials/stateful-application/basic-stateful-set/#scaling-a-statefulset" rel="noreferrer">https://kubernetes.io/docs/tutorials/stateful-application/basic-stateful-set/#scaling-a-statefulset</a>, I would like to ask how to achieve zero-downtime rolling update? I guess here are the minimum requirements:</p>

<p>(1) .spec.updateStrategy set to RollingUpdate</p>

<p>(2) .spec.podManagementPolicy set to OrderedReady</p>

<p>(3) .spec.replicas set to 2</p>

<p>Is that right? And I assume that when update is happening in reverse order, all traffic to the StatefulSet is served by the  pods with lower ordinal number?</p>

Kok How Teh
<p>Yes to have have zero downtime for <code>statefulsets</code> upgrade, you should have all the points mentioned:</p>

<ol>
<li><code>.spec.updateStrategy</code> set to <code>RollingUpdate</code></li>
<li><code>.spec.podManagementPolicy</code> set to <code>OrderedReady</code> which is by default <code>OrderedReady</code></li>
<li><code>.spec.replicas</code> set to minimum 2. </li>
</ol>

<p>Another, thing you need to make sure your statefulset doesn't have downtime is proper <code>readiness</code> probe set. The <code>readiness</code> probe tells kubernetes controller manager that this pod is ready to serve request and you can start sending the requests to it.</p>

<p>The reason it is very important while doing zero downtime upgrade is lets say you have two replica's of statefulset and you started rolling upgrade without readiness probe set. The kubernetes will delete the pod in reverse order and make it come to running state and mark it as ready and terminate another pod. Now lets say your container process didn't come up in that time there will be no pod to serve the requests, because one pod is not completely ready yet and kubernetes has terminated another pod for upgrade process and hence the data loss.</p>

<pre><code>readinessProbe:
  httpGet:
    path: /
    port: 80
  initialDelaySeconds: 5
  periodSeconds: 5
  successThreshold: 1
</code></pre>

<p>EDIT: The following json snippet I use for rolling update of statefulsets in my case:</p>

<pre><code> "spec": {
         "containers": [
           {
             "name": "md",
             "image": "",
             "imagePullPolicy": "IfNotPresent",
             "command": [
               "/bin/sh",
               "-c"
             ],
             "args": [
               "chmod -R 777 /logs/; /on_start.sh"
             ],
             "readinessProbe": {
                "exec": {
                   "command": [
                      "cat",
                      "/tmp/ready.txt"
                   ]
                 },
                 "failureThreshold": 10,
                 "initialDelaySeconds": 5,
                 "periodSeconds": 5,
                 "successThreshold": 1,
                 "timeoutSeconds": 1
             },
             "securityContext": {
               "privileged": true
             }
      }
</code></pre>

<p>This is how you can setup readiness probe in your statefulset containers. I am setting readiness probe as <code>linux command</code>, if you have http probe then it will be different.</p>
