<p>I am confused about the <code>previous</code> parameter in the <a href="https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.19/#read-log-pod-v1-core" rel="nofollow noreferrer">Read Pod Log API</a> in Kubernetes. The parameter called <code>previous</code> has this description in the Kubernetes API documentation:</p>
<p><code>Return previous terminated container logs. Defaults to false.</code></p>
<p>What exactly does this mean or do? I decided to try and investigate the behavior around this and I came up with the following example. Consider this simple pod:</p>
<pre><code>apiVersion: v1
kind: Pod
metadata:
  name: log-pod-demo
spec:
  containers:
  - name: log-container
    image: ubuntu
    command: [ &quot;/bin/sh&quot;, &quot;-c&quot;, &quot;echo 'Hello, World!'; echo 'Hello!'; echo 'Hola!'; echo 'OK I AM DONE NOW'&quot; ]
</code></pre>
<p>If I run <code>kubectl apply -f log-pod-demo.yaml</code> followed by <code>kubectl logs log-pod-demo -p</code>, kubectl returns the expected log messages (<code>Hello, World!, Hello, Hola, OK I AM DONE NOW</code>). At other times kubectl returns this error: <code>unable to retrieve container logs for docker://1ceb99245689d3616bcace8de7b7dfcdbab297258e3b37b92340f7deb4a3e62f</code>. See a picture of this here:</p>
<p><a href="https://i.stack.imgur.com/SipEu.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/SipEu.png" alt="enter image description here" /></a></p>
<p>I can't figure out what's going on. When I omit the <code>-p</code> parameter I do not get any errors. I also tried adding some additional logging to the <code>kubectl</code> command like this: <code>kubectl logs log-pod-demo -p -v=99</code> and I get this error: <code>previous terminated container \&quot;log-container\&quot; in pod \&quot;log-pod-demo\&quot; not found</code>.</p>
<p>I am confused by this behavior and I don't understand what adding this parameter is supposed to do. Can someone please explain what the purpose of the <code>previous</code> parameter is, when I would want to use it and why I am getting these errors?</p>

Rob L
<p>Here is what my kubectl help shows:</p>
<pre><code>$ kubectl logs --help | grep '\-\-previous'
  -p, --previous=false: If true, print the logs for the previous instance of the container in a pod if it exists.
</code></pre>
<p>My help message is different than yours because (according to <a href="https://github.com/kubernetes/kubernetes/commit/3a3633a32ec83675b63c126932d00390165d3d54" rel="nofollow noreferrer">this commit</a>) you are using kubectl version 1.11 or older and I also belive that new help provides more clear explaination for this parameter.</p>
<p>But to further explain it to you, lets think why this is usefull. Immagine, that some container got restarted and you want to know why. It would be very hard to tell if you didn't keep any logs from before restart happened. Since the logs are kept, you can recall them using --previous flag and hopefully find the issue that caused it.</p>
