Skip to content

Commit c5e0436

Browse files
committed
feat(k8s): cron jobs
1 parent 0503e98 commit c5e0436

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

app/job-cron.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
apiVersion: batch/v1beta1
2+
kind: CronJob
3+
metadata:
4+
name: training-job-cron
5+
spec:
6+
schedule: "*/1 * * * *"
7+
jobTemplate:
8+
spec:
9+
template:
10+
spec:
11+
containers:
12+
- name: training-job-cron
13+
image: busybox
14+
command: ['sh', '-c', 'date; echo Hello from the Kubernetes cluster']
15+
restartPolicy: OnFailure

commands.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,13 @@ kubectl create -f ./job-parallel-queue.yaml
6666
jobsArray=($(echo $(kubectl get pods --show-all --selector=job-name=training-job-parallel --output=jsonpath={.items..metadata.name}) | tr ' ' '\n'))
6767
kubectl logs ${jobsArray[1]}
6868
kubectl logs ${jobsArray[2]}0
69+
70+
### cron job ###
71+
kubectl create -f ./job-cron.yaml
72+
kubectl get cronjob training-job-cron
73+
# this will create a cronjob which is going to create a job in every minute
74+
# if you want to see the logs of a job: get jobs, select one from the cron, find its pod and log it
75+
# kubectl get jobs
76+
# pod=$(kubectl get pods -a --selector=job-name=training-job-cron-1516207920 --output=jsonpath={.items..metadata.name})
77+
# kubectl logs $pod
78+
kubectl delete cronjob hello

0 commit comments

Comments
 (0)