<p>Assume I have a Kubernetes <code>CronJob</code></p>
<pre><code>apiVersion: batch/v1beta1
kind: CronJob
metadata:
  name: cron-job-logging
spec:
  schedule: &quot;@hourly&quot;
  jobTemplate:
    spec:
      template:
        spec:
          containers:
          - name: cron-job-logging
            image: python:3
            args:
            - /usr/bin/python3
            - -c
            - import random; print('a') if random.random() &lt; 0.5 else print('b')
          restartPolicy: OnFailure
</code></pre>
<p>which runs on a GKE cluster 1.14.x with Cloud Operation for GKE activated for &quot;System and workload logging and monitoring&quot;.</p>
<p>How can I collect the output for period t (let's say a month) so that I can see whether the pod printed <code>a</code> or <code>b</code>.</p>
<p>If seen some issues about this request, like <a href="https://github.com/kubernetes/kubernetes/issues/27768" rel="nofollow noreferrer">https://github.com/kubernetes/kubernetes/issues/27768</a>. The logs seem to be available for some users, but not for others which might be caused by the fact that <code>CronJobs</code> are a beta feature.</p>

Kalle Richter
<p>I've deployed your cronjob, and just for example purposes I set schedule to run each 1 minute, Below there are a few ways on how to access it:</p>
<ul>
<li><p><strong>GKE console</strong>  – In the  <a href="https://console.cloud.google.com/kubernetes/workload" rel="nofollow noreferrer">Google Kubernetes Engine</a>  section of Google Cloud Console, select the Kubernetes resources listed in  <strong>Workloads</strong>, and then the  <strong>Container</strong>  or  <strong>Audit Logs</strong>  links, this method is kind of a shortcut for the next option: <em>cloud logging console</em></p>
</li>
<li><p><strong>Cloud Logging console</strong>  – You can see your logs directly from the  <a href="https://console.cloud.google.com/logs" rel="nofollow noreferrer">Cloud Logging console</a>  by using the logging filters to select the Kubernetes resources, such as cluster, node, namespace, pod, or container logs. Here are sample  <a href="https://cloud.google.com/logging/docs/view/query-library-preview#kubernetes-filters" rel="nofollow noreferrer">Kubernetes-related queries</a>  to help get you started.</p>
<ul>
<li>This is the query I used (redacted project details):
<pre><code>resource.type=&quot;k8s_container&quot;
resource.labels.project_id=&quot;PROJECT_NAME&quot;
resource.labels.location=&quot;ZONE&quot;
resource.labels.cluster_name=&quot;CLUSTER_NAME&quot;
resource.labels.namespace_name=&quot;NAMESPACE&quot;
labels.k8s-pod/job-name:&quot;cron-job-logging-&quot;
</code></pre>
</li>
<li>Here are the result:
<a href="https://i.stack.imgur.com/HwO0p.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/HwO0p.png" alt="enter image description here" /></a></li>
</ul>
</li>
<li><p><strong>Cloud Monitoring console</strong>  – If you have enabled a Cloud Monitoring Workspace, in the  <a href="https://console.cloud.google.com/monitoring/dashboards/resourceList/kubernetes" rel="nofollow noreferrer">Kubernetes Engine</a>  section of the Cloud Monitoring console, select your  <a href="https://cloud.google.com/stackdriver/docs/solutions/gke/observing#alerting-details" rel="nofollow noreferrer">cluster, nodes, pod, or containers</a>  to view your logs.</p>
</li>
<li><p><strong><code>gcloud</code>  command-line tool</strong>  – Using the  <a href="https://cloud.google.com/logging/docs/reference/tools/gcloud-logging" rel="nofollow noreferrer"><code>gcloud logging read</code></a>  command, select the appropriate cluster, node, pod, and container logs.</p>
</li>
<li><p>Here an example:</p>
</li>
</ul>
<pre class="lang-sh prettyprint-override"><code>$ gcloud logging read &quot;resource.labels.project_id=PROJECT AND resource.labels.cluster_name=CLUSTER_NAME AND labels.k8s-pod/job-name:cron-job-logging-&quot;
---
insertId: 6vorvd43akuvy8fi3
labels:
  k8s-pod/controller-uid: c525bbae-c6c9-11ea-931b-42010a80001f
  k8s-pod/job-name: cron-job-logging-1594838040
logName: projects/PROJECT/logs/stdout
receiveTimestamp: '2020-07-15T18:35:14.937645549Z'
resource:
  labels:
    cluster_name: CLUSTER_NAME
    container_name: cron-job-logging
    location: ZONE
    namespace_name: default
    pod_name: cron-job-logging-1594838040-pngsk
    project_id: PROJECT
  type: k8s_container
severity: INFO
textPayload: |
  a
timestamp: '2020-07-15T18:34:09.907735144Z'
</code></pre>
<p>More info here: <a href="https://cloud.google.com/stackdriver/docs/solutions/gke/using-logs" rel="nofollow noreferrer">GKE - Using Logs</a></p>
<p>If you have any question, let me know in the comments.</p>
