<p>I am running a number of <a href="https://kubernetes.io/docs/concepts/workloads/controllers/cron-jobs/" rel="nofollow noreferrer">CronJobs</a> to automate tasks on my home server. When a Job runs and its Pods complete, I can view logs using <code>kubectl logs &lt;podName&gt;</code>, however after a certain amount of time (less than 5mins but more than 30s) the Pod still exists in Kubernetes but I get:</p>

<pre><code>unable to retrieve container logs for docker://&lt;containerID&gt;
</code></pre>

<p>I have not enabled any log rotation myself so I assume Docker is cleaning up the logs once the container finishes. How can I configure Docker to retain these container logs so that I can see the Jobs logs after a longer period of time (say 1 day) after the Job completes.</p>

<ul>
<li>Cluster provisioner: kubeadm 1.17.0</li>
<li>Kubernetes version: 1.17.0</li>
<li>Docker version: 18.06.3-ce</li>
<li><code>uname -r</code>: 4.19.86-coreos</li>
</ul>

dippynark
<p>You can try setting up <code>minimum-container-ttl-duration</code> flag in Kubelet. This is  the minimum age for a finished container before it is garbage collected.</p>

<p>Also in the job spec you can specify a TTL</p>

<pre><code>apiVersion: batch/v1
kind: Job
metadata:
  name: pi-with-ttl
spec:
  ttlSecondsAfterFinished: 100
</code></pre>

<p>The Job pi-with-ttl will be eligible to be automatically deleted, 100 seconds after it finishes.</p>
