<p>I'm using kubernetes 1.21 cronjob to schedule a few jobs to run at a certain time every day.</p>
<p>I scheduled a job to be run at 4pm, via <code>kubectl apply -f &lt;name of yaml file&gt;</code>. Subsequently, I updated the yaml <code>schedule: &quot;0 22 * * *&quot;</code> to trigger the job at 10pm, using the same command <code>kubectl apply -f &lt;name of yaml file&gt;</code>
However, after applying the configuration at around 1pm, the job still triggers at 4pm (shouldn't have happened), and then triggers again at 10pm (intended trigger time).</p>
<p>Is there an explanation as to why this happens, and can I prevent it?</p>
<p>Sample yaml for the cronjob below:</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: batch/v1
kind: CronJob
metadata:
  name: job-name-1
spec:
  schedule: &quot;0 16 * * *&quot; # 4pm
  successfulJobsHistoryLimit: 1
  failedJobsHistoryLimit: 1
  jobTemplate:
    spec:
      template:
        spec:
          containers:
            - image: sample-image
              name: job-name-1
              args:
                - node
                - ./built/script.js
              env:
                - name: NODE_OPTIONS
                  value: &quot;--max-old-space-size=5000&quot;
          restartPolicy: Never
          nodeSelector:
            app: cronjob
</code></pre>
<p>I'm expecting the job to only trigger at 10pm.</p>
<p>Delete the cronjob and reapply it seems to eliminate such issues, but there are scenarios where I cannot the delete the job (because it's still running).</p>

kitkatsim
<ol>
<li>As you use <code>kubectl apply -f &lt;name of yaml file&gt;</code> to schedule a second Job at 10pm which means it will schedule a new Job but it will not replace the existing job. so the reason was that the Job at 4pm also scheduled and it runned.</li>
</ol>
<p>Instead you need to use the below command to replace the Job with another scheduled Job.</p>
<pre><code>kubectl patch cronjob my-cronjob -p '{&quot;spec&quot;:{&quot;schedule&quot;: &quot;0 22 * * *&quot;}}'
</code></pre>
<p>This will run Job only at 10Pm.</p>
<ol start="2">
<li>In order to delete the running Job use the below Process :</li>
</ol>
<p>run in console:</p>
<pre><code>crontab -e
</code></pre>
<p>then you will get crontab opened with an editor, simply delete the line there, save the file and quit the editor - that's it.</p>
<p>if you are running with a root user then use the below command and proceed as above step.</p>
<pre><code>sudo crontab -e  
</code></pre>
