<p>My understanding is that the <code>AGE</code> shown for a pod when using <code>kubectl get pod</code>, shows the time that the pod has been running since the last restart. So, for the pod shown below, my understanding is that it intially restarted 14 times, but hasn't restarted in the last 17 hours. Is this correct, and where is a kubernetes reference that explains this?</p>
<p><a href="https://i.stack.imgur.com/uW3sY.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/uW3sY.png" alt="enter image description here" /></a></p>

<p>Hope you're enjoying your Kubernetes journey !</p>
<p>In fact, the AGE Headers when using kubectl get pod shows you for how long your <strong>pod</strong> has been created and it's running. But do not confuse POD and container:</p>
<p>The header &quot;RESTARTS&quot; is actually linked to the parameters &gt; '.status.containerStatuses[0].restartCount' of the pod manifest. That means that this header is linked to the number of restarts, not of the pod, but of the container inside the pod.</p>
<p>Here is an example:
I just deployed a new pod:</p>
<pre><code>NAME                       READY   STATUS    RESTARTS   AGE
test-bg-7d57d546f4-f4cql   2/2     Running   0          9m38s
</code></pre>
<p>If I check the yaml configuration of this pod, we can see that in the &quot;status&quot; section we have the said &quot;restartCount&quot; field:</p>
<pre><code>❯ k get po test-bg-7d57d546f4-f4cql -o yaml
apiVersion: v1
kind: Pod
metadata:
...
spec:
...
status:
...
  containerStatuses:
  ...
  - containerID: docker://3f53f140f775416644ea598d554e9b8185e7dd005d6da1940d448b547d912798
    ...
    name: test-bg
    ready: true
    restartCount: 0
    ...
</code></pre>
<p>So, to demonstrate what I'm saying, I'm going to connect into my pod and kill the main process's my pod is running:</p>
<pre><code>❯ k exec -it test-bg-7d57d546f4-f4cql -- bash
I have no name!@test-bg-7d57d546f4-f4cql:/tmp$ ps aux
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
1000         1  0.0  0.0   5724  3256 ?        Ss   03:20   0:00 bash -c source /tmp/entrypoint.bash
1000        22  1.5  0.1 2966140 114672 ?      Sl   03:20   0:05 java -jar test-java-bg.jar
1000        41  3.3  0.0   5988  3592 pts/0    Ss   03:26   0:00 bash
1000        48  0.0  0.0   8588  3260 pts/0    R+   03:26   0:00 ps aux
I have no name!@test-bg-7d57d546f4-f4cql:/tmp$ kill 22
I have no name!@test-bg-7d57d546f4-f4cql:/tmp$ command terminated with exit code 137
</code></pre>
<p>and after this, if I reexecute the &quot;kubectl get pod&quot; command, I got this:</p>
<pre><code>NAME                       READY   STATUS    RESTARTS   AGE
test-bg-7d57d546f4-f4cql   2/2     Running   1          11m
</code></pre>
<p>Then, if I go back to my yaml config, We can see that the restartCount field is actually linked to my container and not to my pod.</p>
<pre><code>❯ k get po test-bg-7d57d546f4-f4cql -o yaml
apiVersion: v1
kind: Pod
metadata:
...
spec:
...
status:
...
  containerStatuses:
  ...
  - containerID: docker://3f53f140f775416644ea598d554e9b8185e7dd005d6da1940d448b547d912798
    ...
    name: test-bg
    ready: true
    restartCount: 1
    ...
</code></pre>
<p>So, to conclude, the <strong>RESTARTS</strong> header is giving you the restartCount of the container not of the pod, but the <strong>AGE</strong> header is giving you the age of the pod.</p>
<p>This time, if I delete the pod:</p>
<pre><code>❯ k delete pod test-bg-7d57d546f4-f4cql
pod &quot;test-bg-7d57d546f4-f4cql&quot; deleted
</code></pre>
<p>we can see that the restartCount is back to 0 since its a brand new pod with a brand new age:</p>
<pre><code>NAME                       READY   STATUS        RESTARTS   AGE
test-bg-7d57d546f4-bnvxx   2/2     Running       0          23s
test-bg-7d57d546f4-f4cql   2/2     Terminating   2          25m
</code></pre>
<p>For your example, it means that the <strong>container</strong> restarted 14 times, but the pod was deployed 17 hours ago.</p>
<p>I can't find the exact documentation of this but (as it is explained here: <a href="https://kubernetes.io/docs/concepts/workloads/_print/#working-with-pods" rel="noreferrer">https://kubernetes.io/docs/concepts/workloads/_print/#working-with-pods</a>):
&quot;Note: Restarting a container in a Pod should not be confused with restarting a Pod. A Pod is not a process, but an environment for running container(s). A Pod persists until it is deleted.&quot;</p>
<p>Hope this has helped you better understand.
Here is a little tip from <a href="https://kubernetes.io/docs/reference/kubectl/cheatsheet/" rel="noreferrer">https://kubernetes.io/docs/reference/kubectl/cheatsheet/</a>:
kubectl get pods --sort-by='.status.containerStatuses[0].restartCount'
(to sort your pods by their restartCount number :p)</p>
<p>Bye</p>
