title: Cron Jobs in Kubernetes - connect to existing Pod, execute script
body: <p>I'm certain I'm missing something obvious. I have looked through the documentation for ScheduledJobs / CronJobs on Kubernetes, but I cannot find a way to do the following on a schedule:</p>
  
  <ol>
  <li>Connect to an existing Pod</li>
  <li>Execute a script</li>
  <li>Disconnect</li>
  </ol>
  
  <p>I have alternative methods of doing this, but they don't feel right. </p>
  
  <ol>
  <li><p>Schedule a cron task for: kubectl exec -it $(kubectl get pods --selector=some-selector | head -1) /path/to/script</p></li>
  <li><p>Create one deployment that has a "Cron Pod" which also houses the application, and many "Non Cron Pods" which are just the application. The Cron Pod would use a different image (one with cron tasks scheduled).</p></li>
  </ol>
  
  <p>I would prefer to use the Kubernetes ScheduledJobs if possible to prevent the same Job running multiple times at once and also because it strikes me as the more appropriate way of doing it.</p>
  
  <p>Is there a way to do this by ScheduledJobs / CronJobs?</p>
  
  <p><a href="http://kubernetes.io/docs/user-guide/cron-jobs/" rel="noreferrer">http://kubernetes.io/docs/user-guide/cron-jobs/</a></p>