<p>I have been playing around with minikube and after a set of operations, the output of <code>kubectl get pod -w</code> is like this-</p>

<pre><code>
nginx   1/1   Running   2     10m
nginx   1/1   Running   3     10m
nginx   0/1   Completed   2     10m
nginx   0/1   CrashLoopBackOff   2     11m
nginx   1/1   Running   3     11m
nginx   1/1   Running   3     12m
</code></pre>

<p>I don't understand the count shown at line 3 and 4. What does restart count convey exactly?</p>

Shadja Chaudhari
<p>RestartCount represents the number of times the container inside a pod has been restarted, it is based on the number of dead containers that have not yet been removed. Note that this is calculated from dead containers. </p>

<p><code>-w</code> on the command is for watch flag and various headers are as listed below</p>

<pre><code>$ kubectl get pods -w
NAME      READY   STATUS    RESTARTS   AGE
nginx     1/1     Running   0          21m
</code></pre>

<p>To get detailed output use <code>-o wide</code> flag</p>

<pre><code>$ kubectl get pods -o wide
NAME      READY   STATUS    RESTARTS   AGE   IP            NODE                    NOMINATED NODE   READINESS GATES
nginx   1/1     Running   1          21h   10.244.2.36   worker-node-2   &lt;none&gt;           &lt;none&gt;

</code></pre>

<p>So the READY field represents the containers inside the pods and can be seen in detailed by describe pod command. Refer <a href="https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/#pod-conditions" rel="nofollow noreferrer">POD Lifecycle</a></p>

<pre><code>$ kubectl describe pod nginx| grep -i -A6 "Conditions"
Conditions:
  Type              Status
  Initialized       True
  Ready             True
  ContainersReady   True
  PodScheduled      True
</code></pre>

<p>RESTARTS Field is tracked under Restart Count , grep it from pod description as below. </p>

<pre><code>$ kubectl describe pod nginx | grep -i "Restart"
    Restart Count:  0
</code></pre>

<p>So as a test we now try to restart the above container and see what field are updated.
We find the node where our container is running and kill the container from node using docker command and it should be restarted automatically by kubernetes </p>

<pre><code>$ kubectl get pods -o wide
NAME     READY   STATUS    RESTARTS   AGE   IP            NODE                    NOMINATED NODE   READINESS GATES
nginx   1/1     Running   0          21h   10.244.2.36   worker-node-2   &lt;none&gt;           &lt;none&gt;
</code></pre>

<pre><code>ubuntu@worker-node-2:~$ sudo docker ps  -a | grep -i nginx
4c8e2e6bf67c        nginx                    "nginx -g 'daemon of…"   22 hours ago        Up 22 hours                                  


ubuntu@worker-node-2:~$ sudo docker kill 4c8e2e6bf67c
4c8e2e6bf67c
</code></pre>

<ol>
<li>POD Status is changed to ERROR</li>
<li>READY count goes to 0/1</li>
</ol>

<pre><code>ubuntu@cluster-master:~$ kubectl get pods -o wide
NAME   READY   STATUS   RESTARTS   AGE   IP            NODE            NOMINATED NODE   READINESS GATES
nginx   0/1      Error    0          21h   10.244.2.36  worker-node-2   &lt;none&gt;           &lt;none&gt;
</code></pre>

<p>Once POD recovers the failed container.</p>

<ol>
<li>READY count is 1/1 again</li>
<li>STATUS changes back to running</li>
<li>RESTARTS count is incremented by 1</li>
</ol>

<pre><code>ubuntu@cluster-master:~$ kubectl get pods -o wide
NAME    READY   STATUS    RESTARTS   AGE   IP            NODE            NOMINATED NODE   READINESS GATES
nginx   1/1     Running   1          21h   10.244.2.36   worker-node-2   &lt;none&gt;           &lt;none&gt;

</code></pre>

<p>Check restart by describe command as well</p>

<pre><code>$ kubectl describe pods nginx  | grep -i "Restart"
    Restart Count:  1
</code></pre>

<p><strong>The values in your output are not inconsistent</strong> .. that is how the pod with a <code>restartPolicy of Always</code> will work it will try to bring back the failed container until CrashLoopBackOff limit is reached. </p>

<p>Refer <a href="https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/#example-states" rel="nofollow noreferrer">POD State Examples</a></p>

<p>Pod is running and has one Container. Container exits with success.
Log completion event.</p>

<p>If restartPolicy is:</p>

<ol>
<li>Always: Restart Container; Pod phase stays Running.</li>
<li>OnFailure: Pod phase becomes Succeeded.</li>
<li>Never: Pod phase becomes Succeeded.</li>
</ol>
