CodexBloom - Programming Q&A Platform

Kubernetes CronJob Not Executing in Time Zone Other Than UTC - Time Discrepancies

👀 Views: 0 đŸ’Ŧ Answers: 1 📅 Created: 2025-07-02
kubernetes cronjob timezone YAML

I'm refactoring my project and After trying multiple solutions online, I still can't figure this out. I'm experiencing issues with a Kubernetes CronJob that seems to not execute at the expected times when set to a time zone other than UTC... I've defined my CronJob like this: ```yaml apiVersion: batch/v1 kind: CronJob metadata: name: my-cronjob spec: schedule: "0 8 * * *" # Should run at 8 AM local time jobTemplate: spec: template: spec: containers: - name: my-container image: my-image:latest command: ["/bin/sh", "-c", "echo Hello from the CronJob"] restartPolicy: OnFailure ``` My cluster is running in a different time zone (PST) and I've also configured the timezone in my pod as follows: ```yaml spec: containers: - name: my-container image: my-image:latest env: - name: TZ value: "America/Los_Angeles" ``` Despite this, the CronJob continues to run based on UTC timing, which means it executes at 8 AM UTC (1 AM PST) instead of the intended 8 AM PST. I've checked the Kubernetes version (v1.23.0) and verified that the timezone settings in my container should work. I also tried adding the timezone directly in the CronJob spec using annotations, but it didn't help. Any advice on how to ensure that my CronJob runs according to the local time zone instead of defaulting to UTC? Are there additional configurations or best practices I might be missing? I'm working on a web app that needs to handle this. How would you solve this? This is part of a larger web app I'm building. What's the best practice here? I'm on Ubuntu 20.04 using the latest version of Yaml. I'm developing on macOS with Yaml. What are your experiences with this?