CronJobs and Jobs aren’t in CKA, but are in CKAD
Create a job called dicey using
kodekloud/throw-dice
The image generates a random number between 1 and 6 and exits. It is a success only if it is a 6 else it is a failure. Check how many times it takes the job to trigger to get a successful outcome.
# create the job
kubectl create job dicey --image=kodekloud/throw-dice
# check - you should see how many attempts before rolling a 6
kubectl get pods
kubectl logs <pod name>
Create a job with the above image to
completions reference parallelism reference backofflimit reference
#create a job
kubectl create job dicey2 --image=kodekloud/throw-dice --dry-run=client -o yaml > dicey2.yaml
# edit it so it looks like this
apiVersion: batch/v1
kind: Job
metadata:
name: dicey2
spec:
completions: 8
parallelism: 3
backoffLimit: 15
template:
metadata:
spec:
containers:
- image: kodekloud/throw-dice
name: dicey2
restartPolicy: Never
# execute the file
kubectl apply -f dicey2.yaml
# check the output
kubectl get jobs
kubectl get pods -l job-name=dicey2
# pick a failed and a succesful job
kubectl logs <pod name>
Create a Cronjob called echo-me using
busybox
date; echo hello from kubernetes cluster
# create the job
kubectl create cronjob echo-me --image=busybox --schedule="*/2 * * * *" -- "sh" "-c" "date ; echo hello from kubernetes cluster"
# check - you should see the output in the logs after 2 minutes, be patient
kubectl get cronjobs
kubectl describe cronjobs echo-me
# wait 2 minutes
kubectl get jobs
kubectl get pods
# select a pod with echo-me.....
kubectl logs <pod name>
Thu Feb 3 13:52:02 UTC 2022
hello from kubernetes cluster