<p>I created a <a href="https://kubernetes.io/docs/concepts/workloads/controllers/cron-jobs/" rel="nofollow noreferrer">CronJob</a> resource in Kubernetes.</p>
<p>I want to check the logs to validate that my crons are run. But not able to find any way to do that. I have gone through the <a href="https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands#logs" rel="nofollow noreferrer">commands</a> but looks like all are for pod resource type.</p>
<p>Also tried following</p>
<pre class="lang-sh prettyprint-override"><code>$ kubectl logs cronjob/&lt;resource_name&gt;
error: cannot get the logs from *v1beta1.CronJob: selector for *v1beta1.CronJob not implemented
</code></pre>
<p>Questions:</p>
<ol>
<li><p>How to check logs of CronJob Resource type?</p>
</li>
<li><p>If I want this resource to be in specific namespace, how to implement that same?</p>
</li>
</ol>

codeaprendiz
<p>You need to check the logs of the pods which are created by the cronjob. The pods will be in completed state but you can check logs.</p>

<pre><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>

<p>For creating a cronjob in a <code>namespace</code> just add namespace in <code>metadata</code> section. The pods will created in that <code>namespace</code>.</p>

<pre><code>apiVersion: batch/v1beta1
kind: CronJob
metadata:
  name: hello
  namespace: default
spec:
  schedule: "*/1 * * * *"
  jobTemplate:
    spec:
      template:
        spec:
          containers:
          - name: hello
            image: busybox
            args:
            - /bin/sh
            - -c
            - date; echo Hello from the Kubernetes cluster
          restartPolicy: OnFailure
</code></pre>

<p>Ideally you should be sending the logs to a log aggregator system such as ELK or Splunk.</p>
