<p>I am writing a test to catch a case where a container fails after 5 minutes.  Once crashed, it gets restarted.  So if I wait 16 minutes, it will have crashed 3 times.</p>
<p>I know I can see the logs of the current container like:</p>
<pre><code>$ kubectl logs podname containername
    service starting at 00:15
    service happy
</code></pre>
<p>And I can see the logs of the previous container like:</p>
<pre><code>kubectl logs --previous podname containername
    service starting at 00:10
    service happy
    service sad
    service CRASHED
</code></pre>
<p>But can I get logs for containers older than one restart ago?  Something like:</p>
<pre><code>kubectl logs --all-previous podname containername # &lt;-- no such command
    service starting at 00:00
    service happy
    service sad
    service CRASHED
    ----
    service starting at 00:05
    service happy
    service sad
    service CRASHED
    ----
    service starting at 00:10
    service happy
    service sad
    service CRASHED
    ----
    service starting at 00:15
    service happy
</code></pre>
<p>If my test detects that it has crashed <em>at all</em> I want to capture logs that tell the whole story, not just the previous crash.</p>
<p>If there isn't a command that will aggregate logs for me, then can I at least find the logs one-at-a-time so that I can aggregate them myself?  If so, where would I look?</p>

MatrixManAtYrService
<p>The container must exist in the underlying runtime to get the logs, and they are cleaned up by kubernetes.</p>
<p>A log aggregator like <a href="https://www.fluentd.org/" rel="nofollow noreferrer">fluentd</a> is the standard way to collect logs from each container runtime to a central location. You can write the logs to a simple <a href="https://docs.fluentd.org/output/file" rel="nofollow noreferrer">file</a> to avoid a large ingest system and query with <code>jq</code>.</p>
