1

I am trying to setup cronjobs in my kubernetes cluster,I have micro service that import data from another api to my database. I want to run this command every 10 minutes. I have following cronjob manifest

apiVersion: v1
items:
- apiVersion: batch/v1beta1
  kind: CronJob
  metadata:
    labels:
      chart: cronjobs-0.1.0
    name: cron-cronjob1
    namespace: default
  spec:
    concurrencyPolicy: Forbid
    failedJobsHistoryLimit: 1
    jobTemplate:      
      spec:
        template:
          metadata:          
            labels:
              app: cron
              cron: cronjob1
          spec:
            containers:
              command: ["/usr/local/bin/php"]
              args: ["artisan bulk:import"]
              env:
              - name: DB_CONNECTION
                value: postgres
              - name: DB_HOST
                value: postgres
              - name: DB_PORT
                value: "5432"
              - name: DB_DATABASE
                value: xxx
              - name: DB_USERNAME
                value: xxx
              - name: DB_PASSWORD
                value: xxxx
              - name: APP_KEY
                value: xxxxx
              image: registry.xxxxx.com/xxxx:2ecb785-e927977
              imagePullPolicy: IfNotPresent
              name: cronjob1
              ports:
              - containerPort: 80
                name: http
                protocol: TCP              
            imagePullSecrets:
            - name: xxxxx
            restartPolicy: OnFailure          
            terminationGracePeriodSeconds: 30
    schedule: '* * * * *'
    successfulJobsHistoryLimit: 3

I am getting following error when cronjob scheduler spin up a pod

Could not open input file: artisan bulk:import

How to resolve this?

Prafull Ladha
  • 12,341
  • 2
  • 37
  • 58
Jack
  • 1,162
  • 3
  • 12
  • 27

2 Answers2

1

Assuming file artisan exists and php can execute it:

command: ["/usr/local/bin/php"]
args: ["artisan", "bulk:import"]

This way there will be two arguments passed to php instead of one which php assumes is the file to execute.

apisim
  • 4,036
  • 1
  • 10
  • 16
1

here is the fix

   args:
      - "/bin/bash"
      - "-c"
      - "/var/www/html/artisan bulk:import"
Jack
  • 1,162
  • 3
  • 12
  • 27