I need to run a third part API in schedulded interval from k8s cluster. I have tried with k8s corn job but its not working getting error as invalid command . I am using below script. Can anyone suggest how to use it
apiVersion: batch/v1beta1
kind: CronJob
metadata:
name: corn-job
namespace: scheduler
spec:
schedule: "5 * * * *"
jobTemplate:
spec:
template:
spec:
containers:
- name: hello
image: busybox
args:
- /bin/sh
- -c curl http://google.com
restartPolicy: OnFailure
busybox image doesnt have curl binary. it wont work. use the below yaml or update the image
apiVersion: batch/v1beta1
kind: CronJob
metadata:
name: cron-demo
spec:
schedule: "*/1 * * * *"
jobTemplate:
spec:
template:
spec:
containers:
- name: hello
image: ekambaram/curl
command: ["curl"]
args: ["http://google.com"]
restartPolicy: OnFailure
just tested it and find below the output
master $ kubectl get po
NAME READY STATUS RESTARTS AGE
corn-job-1574850360-srwf6 0/1 Completed 0 44s
master $ kubectl logs -f corn-job-1574850360-srwf6
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
<TITLE>301 Moved</TITLE></HEAD><BODY>
<H1>301 Moved</H1>
The document has moved
<A HREF="http://www.google.com/">here</A>.
</BODY></HTML>
100 219 100 219 0 0 39 0 0:00:05 0:00:05 --:--:-- 54