<p>Use case:</p>

<p>I want to be able to re-run a job from where the first job left off.  I am using Helm to deploy into Kubernetes.</p>

<p>I have the idea of saving the state of the first job in a ConfigMap.  The ConfigMap yaml defining the ConfigMap is packaged up with the job and both are deployed at the same time with Helm.  </p>

<pre><code>apiVersion: v1
kind: ConfigMap
metadata:
  name: NameOfMyConfigMap
data:
  someKey: someValue
  MY_STATE: state      &lt;---- See below as to whether this should be included or not
</code></pre>

<p>The job is run with an ENV variable set from the ConfigMap:</p>

<pre><code>env:
  - name: MY_STATE
    valueFrom:
      configMapKeyRef:
        name:  NameOfMyConfigMap
        key: MY_STATE
</code></pre>

<p>The job runs a script that looks to see if $MY_STATE is set and if it is not set then the job is being run for the first time, otherwise the job closes down the already running first job, saves the first job's state into the MY_STATE ConfigMap variable and launches the job again using the saved state.</p>

<p>If I don't declare the MY_STATE key in the initial ConfigMap definition then the first run of the job will fail, as the ENV definition above cannot find the ConfigMap variable.</p>

<p>If I do declare the value (<code>MY_STATE: ""</code>) in the ConfigMap definition, then the first deployment will work.  However, if I re-deploy the job with <code>helm upgrade</code> then does the value I enter in the definition not overwrite an existing value in the existing ConfigMap?</p>

<p>What is the best method of storing state in between runs of the same job?</p>

<p>Have you tried using volumes? In this case it should not be overwritten when using helm upgrade.</p>

<p>Could an example like this work? (From 
<a href="https://groups.google.com/forum/#!msg/kubernetes-users/v2806ezEdPk/1geJCO8-AQAJ" rel="nofollow noreferrer">https://groups.google.com/forum/#!msg/kubernetes-users/v2806ezEdPk/1geJCO8-AQAJ</a>)</p>

<pre><code>apiVersion: batch/v1
kind: Job
metadata:
  name: keystore-configmap-job
spec:
  template:
    metadata:
      name: keystore-configmap
    spec:
      containers:
        - name: keystore
          image: ubuntu
          volumeMounts:
            - name: keystore-configmap-volume
              mountPath: /config-base64
          command: [ "sh", "-c", "cat /config-base64/keystore.jks | base64 --decode | sha256sum" ]

      restartPolicy: Never

      volumes:
      - name: keystore-configmap-volume
        configMap:
          name: keystore-configmap
</code></pre>
