Execute shell script file using kubernetes as a cron job

4/10/2018

When executing yaml file as a cronjob i am getting the following error:

container_linux.go:247: starting container process caused "exec: \"/home/ubuntu/exam.sh\": stat /home/ubuntu/exam.sh: no such file or directory"

job2.yaml file apiVersion: batch/v1beta1 kind: CronJob metadata:   name: ghost   labels:
    role: blog spec:   schedule: "*/1 * * * *"   jobTemplate:
    spec:
      template:
        spec:
          containers:
          - name: ghost
            image: ghost:0.11-alpine
            command: ["/home/ubuntu/exam.sh"]
          restartPolicy: OnFailure

Can any one help me out of this.

-- Chakri Reddy
kubernetes

1 Answer

4/10/2018

With this kind of errors, you should check if the file was really executed by a cronjob, if it exists and is executable. Please check it.

Alternatively, you can run it from kubectl run command:

kubectl run ghost --schedule="*/1 * * * *" --restart=OnFailure --image=ghost:0.11-alpine -- /bin/sh -c "your check script content" 
-- d0bry
Source: StackOverflow