Execute shell script file using kubernetes as a cron job

+1 vote

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.

Sep 27, 2018 in Kubernetes by Hannah
• 18,520 points
17,723 views

4 answers to this question.

+1 vote
Best answer

use /bin/sh instead of /bin/bash

This solved it for a lot of people. Have a look at this GitHub thread.

If you are interested in knowing more about Kubernetes, then consider taking  CKA Certification Course.

answered May 7, 2019 by Sid

selected May 7, 2019 by Kalgi
0 votes

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"
answered Sep 27, 2018 by Kalgi
• 52,350 points
+1 vote
Try updating your docker and check if the error still exists
answered May 7, 2019 by Manasi
+1 vote
I had the same error on windows. Resolved this by running docker as administrator. I don't the how and why behind it though.
answered May 7, 2019 by Yamini

Related Questions In Kubernetes

0 votes
1 answer

Connect to existing pod, execute script, disconnect - Kubernetes cron job

As far as i know there's no ...READ MORE

answered Sep 17, 2018 in Kubernetes by Kalgi
• 52,350 points
4,813 views
0 votes
1 answer

"no such file or directory" error while executing yaml file as a cron job

When you get errors like these, you ...READ MORE

answered Sep 18, 2018 in Kubernetes by Kalgi
• 52,350 points
3,369 views
0 votes
1 answer
0 votes
1 answer

Spark job using kubernetes instead of yarn

I should be in the format of ...READ MORE

answered Sep 6, 2018 in Kubernetes by Kalgi
• 52,350 points
1,018 views
+1 vote
1 answer
0 votes
3 answers

Error while joining cluster with node

Hi Kalgi after following above steps it ...READ MORE

answered Jan 17, 2019 in Others by anonymous
15,474 views
+15 votes
2 answers

Git management technique when there are multiple customers and need multiple customization?

Consider this - In 'extended' Git-Flow, (Git-Multi-Flow, ...READ MORE

answered Mar 27, 2018 in DevOps & Agile by DragonLord999
• 8,450 points
4,034 views
+2 votes
1 answer
0 votes
3 answers

Using multiple commands in a kubernetes yaml file

Try something like this: containers: - name: ...READ MORE

answered Apr 23, 2019 in Kubernetes by lyza
49,873 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP