title: How to run kubectl commands in a cron
body: <p>I created a schedule configuration inside my Gcloud project to create snapshots of a bunch of virtual disks.</p>
  <p>Now I want to add my schedule configuration to my disks, but I dont know how to do it in a automated way, because I have more than 1200 disks.</p>
  <p>I tryed to use a POD with a cron inside, but I cannot execute the kubectl command to list all my persistent volumes:</p>
  <pre><code>kubectl describe pv | grep &quot;Name&quot; | awk 'NR % 2 == 1' | awk '{print $2}'
  </code></pre>
  <p>I want to use this list with the next command in a Loop to add automatically my programmed schedule to my disks:</p>
  <pre><code>gcloud compute disks add-resource-policies [DISK_NAME] --resource-policies [SCHEDULE_NAME] --zone [ZONE]
  </code></pre>
  <p>Thanks in advance for your help.</p>
  <p>Edit 1: After some comments I changed my code to add a Kubernetes CronJob, but the result is the same, the code doesn't work (the pod is created, but it gives me an error: ImagePullBackOff):</p>
  <pre><code>resource &quot;kubernetes_cron_job&quot; &quot;schedulerdemo&quot; {
    metadata {
      name = &quot;schedulerdemo&quot;
    }
    spec {
      concurrency_policy            = &quot;Replace&quot;
      failed_jobs_history_limit     = 5
      schedule                      = &quot;*/5 * * * *&quot;
      starting_deadline_seconds     = 10
      successful_jobs_history_limit = 10
      job_template {
        metadata {}
        spec {
          backoff_limit = 2
          ttl_seconds_after_finished    = 10
          template {
            metadata {}
            spec {
              container {
                name    = &quot;scheduler&quot;
                image   = &quot;imgscheduler&quot;
                command = [&quot;/bin/sh&quot;, &quot;-c&quot;, &quot;date; kubectl describe pv | grep 'Name' | awk 'NR % 2 == 1' | awk '{print $2}'&quot;]
              }
            }
          }
        }
      }
    }
  }
  </code></pre>