mway
mway

Reputation: 643

Access scheduled run time inside Kubertes CronJob

I'm trying run a cron job with Kubernetes. The job executes a program that performs some computation based on the job's scheduled start time. How can my program get access to this value during its execution?

Upvotes: 6

Views: 996

Answers (1)

Max Lobur
Max Lobur

Reputation: 6040

Option 1 (easiest): Put the same value to job container environment variable. I assume you install with helm or similar mechanism, so it should be easy to reuse schedule variable in 2 places.

Option 2: Use a combination of a Role, RoleBinding and ServiceAccount, then use kubectl / language k8s client to retrieve cronjob (you will need to know its name if there's multiple in a namespace) and get schedule from its parameters.

Option 3: https://kubernetes.io/docs/tasks/inject-data-application/environment-variable-expose-pod-information/ This is a variation of 1 but using the resourceFieldRef. Not sure you can refer a cronjob resource tho :(

Upvotes: 1

Related Questions