<p>I have a requirement to run an ad-hoc job, once in a while. The job needs some state to work. Building the state takes a lot of time. So, it is desired to keep the state persistent and reusable in subsequent runs, for a fast turnaround time. I want this job to be managed as K8s pods.</p>

<p>This is a complete set of requirements:</p>

<ol>
<li>Pods will go down after work finish. The K8s controller should not try to bring up the pods.</li>
<li>Each pod should have a persistent volume attached to it. There should be 1 volume per pod. I am planning to use EBS.</li>
<li>We should be able to manually bring the pods back up in future.</li>
<li>Future runs may have more or less replicas than the past runs.</li>
</ol>

<p>I know K8s supports both Jobs and Statefulsets. Is there any Controller which supports both at the same time?</p>

<blockquote>
  <ol>
  <li>Pods will go down after work finish. The K8s controller should not try
  to bring up the pods. </li>
  </ol>
</blockquote>

<p>This is what Jobs do - run to completion. You only control whether you wanna retry on <code>exit &gt; 0</code>.</p>

<blockquote>
  <ol start="2">
  <li>Pods should have a persistent volume attached to
  them. </li>
  </ol>
</blockquote>

<p>Same volume to all? Will they write or only read? What volume backend do you have, AWS EBS or similar? Depending of answers you might want to split input data between few volumes or use separate volumes to write and then finalization job to assemble in 1 volume (kind of map reduce). Or use volume backend which supports multi-mount RW <a href="https://kubernetes.io/docs/concepts/storage/persistent-volumes/#access-modes" rel="nofollow noreferrer">https://kubernetes.io/docs/concepts/storage/persistent-volumes/#access-modes</a> (see table for <code>ReadWriteMany</code>)</p>

<blockquote>
  <ol start="3">
  <li>We should be able to manually bring the pods back up in future.</li>
  </ol>
</blockquote>

<p>Jobs fit here: You launch it when you need it, and it runs till completion.</p>

<blockquote>
  <ol start="4">
  <li>Future runs may have more or less replicas than the past runs.</li>
  </ol>
</blockquote>

<p>Jobs fit here. Specify different <code>completions</code> or <code>parallelism</code> when you launch a job: <a href="https://kubernetes.io/docs/concepts/workloads/controllers/jobs-run-to-completion/#parallel-jobs" rel="nofollow noreferrer">https://kubernetes.io/docs/concepts/workloads/controllers/jobs-run-to-completion/#parallel-jobs</a></p>

<p>StatefulSets are different concept, they mostly used for clustered software which you run continuously and need to persist the role per pod (e.g. shard). </p>
