<p>Seems that <code>kubectl logs</code> doesn't support cronjob. It says</p>

<blockquote>
  <p>error: cannot get the logs from *v1beta1.CronJob: selector for *v1beta1.CronJob not implemented</p>
</blockquote>

<p>Currently I check the logs of all relative jobs one by one.</p>

<p>Is there any simple command or tool to get these logs?</p>

<hr>

<p>I did some research on bash script and modified <a href="https://stackoverflow.com/questions/53647683/how-to-get-logs-of-jobs-created-by-a-cronjob/53648331#53648331">edbighead's answer</a> to better suit my needs.</p>

<pre><code># cronJobGetAllLogs.sh: Get all logs of a cronjob.
# example:
# ./cronJobGetAllLogs.sh [Insert name of cronJob]

jobs=( $(kubectl get jobs --no-headers -o custom-columns=":metadata.name" | awk "/$1-[0-9]+/{print \$1}" | sort -r ) )
for job in "${jobs[@]}"
do
    echo Logs from job $job
    pod=$(kubectl get pods -l job-name=$job --no-headers -o custom-columns=":metadata.name")
    kubectl logs $pod
done
</code></pre>

<p></p>

<pre><code># cronJobGetLatestLog.sh: Get log of latest job initiated by a cronjob.
# example:
# ./cronJobGetLateestLog.sh [Insert name of cronJob]

job=$(kubectl get jobs --no-headers -o custom-columns=":metadata.name" | awk "/$1-[0-9]+/{print \$1}" | sort -r | head -1)
pod=$(kubectl get pods -l job-name=$job --no-headers -o custom-columns=":metadata.name")
kubectl logs $pod
</code></pre>

<p>From documentation of <a href="https://kubernetes.io/docs/concepts/workloads/controllers/cron-jobs/" rel="noreferrer">CronJobs</a> and <a href="https://kubernetes.io/docs/concepts/workloads/controllers/cron-jobs/" rel="noreferrer">Jobs</a></p>
<blockquote>
<p>A Cron Job creates Jobs on a time-based schedule</p>
<p>...</p>
<p>A job creates one or more pods and ensures that a specified number of them successfully terminate.</p>
</blockquote>
<p>All you need is to view logs for a pod that was created for the job.</p>
<ol>
<li><p>Find your job with <code>kubectl get jobs</code>. This will return your CronJob name with a timestamp</p>
</li>
<li><p>Find pod for executed job <code>kubectl get pods -l job-name=your-job-@timestamp</code></p>
</li>
<li><p>Use <code>kubectl logs your-job-@timestamp-id</code> to view logs</p>
</li>
</ol>
<p>Here's an example of bash script that does all the above and outputs logs for every job's pod.</p>
<pre><code>jobs=( $(kubectl get jobs --no-headers -o custom-columns=&quot;:metadata.name&quot;) )
for job in &quot;${jobs[@]}&quot;
do
   pod=$(kubectl get pods -l job-name=$job --no-headers -o custom-columns=&quot;:metadata.name&quot;)
   kubectl logs $pod
done
</code></pre>
