<p>According to documentation (<a href="https://kubernetes.io/docs/concepts/workloads/controllers/cron-jobs/" rel="noreferrer">https://kubernetes.io/docs/concepts/workloads/controllers/cron-jobs/</a>) I can create cron job in k8s with specify timezone like: <code>&quot;CRON_TZ=UTC 0 23 * * *&quot;</code></p>
<p>My deployment file is:</p>
<pre><code>apiVersion: batch/v1
kind: CronJob
metadata:
  name: scheduler
spec:
  schedule: &quot;CRON_TZ=UTC 0 23 * * *&quot;
...
</code></pre>
<p>During the deploy I am getting an error:</p>
<blockquote>
<p>The CronJob &quot;scheduler&quot; is invalid: spec.schedule: Invalid value: &quot;CRON_TZ=UTC 0 23 * * *&quot;: Expected exactly 5 fields, found 6: CRON_TZ=UTC 0 23 * * *</p>
</blockquote>
<p>Cron is working without perfectly timezone (<code>schedule: &quot;0 23 * * *&quot;</code>)</p>
<p>Cluster version is: <code>Kubernetes 1.21.2-do.2</code> - digitalocean.</p>
<p>What is wrong?</p>

<p>The <code>CRON_TZ=&lt;timezone&gt;</code> prefix won't be available yet, not until 1.22. The inclusion in the 1.21 release docs was an error.</p>
<p>Originally, the change adding the syntax was <a href="https://github.com/kubernetes/website/pull/29455/files" rel="nofollow noreferrer">included for 1.22</a>, but it appears someone got confused and <a href="https://github.com/kubernetes/website/pull/29492/files" rel="nofollow noreferrer">moved the documentation over to 1.21</a>.
Supporting the <code>CRON_TZ=&lt;timezone&gt;</code> syntax is accidental, purely because the <a href="https://github.com/robfig/cron" rel="nofollow noreferrer">package used to handle the scheduling</a> was <a href="https://github.com/kubernetes/kubernetes/commit/4b36a5cbe95d9e305d67cfda2ffa87bb3a0ccd47" rel="nofollow noreferrer">recently upgraded to version 3</a>, which added support for the syntax. The package is the key component that makes the syntax possible and is only part of 1.22.</p>
<p>As of <a href="https://github.com/kubernetes/website/commit/b5e83e89448bcb69c095b7a056aa3f5fa4dcd4ed" rel="nofollow noreferrer">November 2021</a> the wording in the documentation has been adjusted to state that <code>CRON_TZ</code> is not officially supported:</p>
<blockquote>
<p><strong>Caution</strong>:</p>
<p>The v1 CronJob API does not officially support setting timezone as explained above.</p>
<p>Setting variables such as <code>CRON_TZ</code> or <code>TZ</code> is not officially supported by the Kubernetes project. <code>CRON_TZ</code> or <code>TZ</code> is an implementation detail of the internal library being used for parsing and calculating the next Job creation time. Any usage of it is not recommended in a production cluster.</p>
</blockquote>
<p>If you can upgrade to 1.24, you can instead use the new <a href="https://kubernetes.io/docs/concepts/workloads/controllers/cron-jobs/#time-zones" rel="nofollow noreferrer"><code>CronJobTimeZone</code> feature gate</a> to enable the new, official, time-zone support added with <a href="https://github.com/kubernetes/enhancements/blob/2853299b8e330f12584624326fee186b56d4614c/keps/sig-apps/3140-TimeZone-support-in-CronJob/README.md" rel="nofollow noreferrer">KEP 3140</a>. Note that this is still an alpha-level feature; hopefully it will reach beta in 1.25. If all goes well, the feature should reach maturity in release 1.27.</p>
<p>With the feature-gate enabled, you can add a <code>timeZone</code> field to your CronJob <code>spec</code>:</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: batch/v1
kind: CronJob
metadata:
  name: scheduler
spec:
  schedule: &quot;0 23 * * *&quot;
  timeZone: &quot;Etc/UTC&quot;
</code></pre>
