<p>I'm running a <em>CronJob</em> in <em>kubernetes</em>, the jobs complete successfully and I log output to the log file inside <code>(path: storage/logs)</code> but I cannot access that file due to the container being in a completed state.</p>
<p>Here is my job <em>yaml</em>:</p>
<pre><code>apiVersion: v1
items:
- apiVersion: batch/v1beta1
  kind: CronJob
  metadata:
    labels:
      chart: cronjobs-0.1.0
    name: cron-cronjob1
    namespace: default
  spec:
    concurrencyPolicy: Forbid
    failedJobsHistoryLimit: 1
    jobTemplate:      
      spec:
        template:
          metadata:          
            labels:
              app: cron
              cron: cronjob1
          spec:
            containers:
            - args:
              - /usr/local/bin/php
              - -c
              - /var/www/html/artisan bulk:import
              env:
              - name: DB_CONNECTION
                value: postgres
              - name: DB_HOST
                value: postgres
              - name: DB_PORT
                value: &quot;5432&quot;
              - name: DB_DATABASE
                value: xxx
              - name: DB_USERNAME
                value: xxx
              - name: DB_PASSWORD
                value: xxxx
              - name: APP_KEY
                value: xxxxx
              image: registry.xxxxx.com/xxxx:2ecb785-e927977
              imagePullPolicy: IfNotPresent
              name: cronjob1
              ports:
              - containerPort: 80
                name: http
                protocol: TCP              
            imagePullSecrets:
            - name: xxxxx
            restartPolicy: OnFailure          
            terminationGracePeriodSeconds: 30
    schedule: '* * * * *'
    successfulJobsHistoryLimit: 3
</code></pre>
<p>Is there anyway I can get my log file content displayed with <code>kubectl log &lt;podname&gt;</code> command or other alternatives?</p>

<p><code>Cronjob</code> runs pod according to the <code>spec.schedule</code>. After completing the task the pod's status will be set as <code>completed</code>, but the <code>cronjob</code> controller doesn't delete the pod after completing. And the log file content still there in the pod's container filesystem. So you need to do:</p>

<pre class="lang-sh prettyprint-override"><code># here  you can get the pod_name from the stdout of the cmd `kubectl get pods`
$ kubectl logs -f -n default &lt;pod_name&gt;
</code></pre>
