Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

363
Views
Pass current date to kubernetes cronjob

I have a docker image that receive an env var name SINCE_DATE.
I have created a cronjob to run that container and I want to pass it the current date.

How can I do it?

Trying this, I get the literal string date -d "yesterday 23:59"

apiVersion: batch/v1beta1
kind: CronJob
metadata:
  name: my-cron
spec:
  schedule: "* * * * *"
  jobTemplate:
    spec:
      template:
        spec:
          restartPolicy: Never
          containers:
          - name: my-cron
            image: {{ .Values.image.repository }}:{{ .Values.image.tag }}
            imagePullPolicy: {{ .Values.image.pullPolicy }}
            env:
            - name: SINCE_DATE
              value: $(date -d "yesterday 23:59")
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

You could achieve it by overwriting container Entrypoint command and set environment variable. In your case it would looks like:

          containers:
          - name: my-cron
            image: nginx
            #imagePullPolicy: {{ .Values.image.pullPolicy }}
            command:
            - bash
            - -c
            - |
                  export SINCE_DATE=`date -d "yesterday 23:59"`
                  exec /docker-entrypoint.sh           

Note:

Nginx docker-entrypoint.sh in located in / If your image have different path, you should use it, for example exec /usr/local/bin/docker-entrypoint.sh

Very similar use-case can be found in this Stack question

What does this solution?

It will overwrite default script set in the container ENTRYPOINT with the same script but beforehand set dynamically environment variable.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!