'How to create cronjob using open-shift UI to call shell script file
Can we create cronjob to make a simple shell script call without image, template information in the YAML file
For example : I have simple shell script which just prints some echo statements. How to create a cronjob to schedule it without image, jobTemplate, container etc...
Please help me with this.
Solution 1:[1]
Short answer: no, you can not
Q: Why do you need that?
if you want to run a simple script, create a Cronjob with a very small footprint image that includesbash
(or the shell of your choice), like bash or alpine (or many others) and pass your command to start your script to args
Solution 2:[2]
cronjob is also run as container in openshift so you need a docker image. you can use apline or rhel universal images and can specially user shell commands against that in your job deployment file.
Solution 3:[3]
No, you can not do it.
Job or Cronjob also runs the container so image is required, if you are not looking forward to creating the docker image
You can use the default Ubuntu (or any other alpine, busybox) image and run the command top of it by passing the argument or commands to it.
Example
apiVersion: batch/v1
kind: CronJob
metadata:
name: hello
spec:
schedule: "* * * * *"
jobTemplate:
spec:
template:
spec:
containers:
- name: hello
image: busybox:1.28
imagePullPolicy: IfNotPresent
command:
- /bin/sh
- -c
- date; echo Hello from the Kubernetes cluster
restartPolicy: OnFailure
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | titou10 |
Solution 2 | Manmohan Mittal |
Solution 3 | Harsh Manvar |