I am writing answer for cronjob question where it asks job to schedule every minute.
Questions:
For this question, please set the context to cluster1
by running:
kubectl config use-context cluster1
In the ckad-job
namespace, schedule a job called learning-every-minute
that prints this message in the shell every minute: I am practicing for CKAD certification
.
In case the container in pod failed for any reason, it should be restarted automatically.
Use busybox:1.28
image for the cronjob!
My answer is:
apiVersion: batch/v1
kind: CronJob
metadata:
annotations:
kubectl.kubernetes.io/last-applied-configuration: |
{"apiVersion":"batch/v1","kind":"CronJob","metadata":{"annotations":{},"creationTimestamp":null,"name":"learning-every-minute","namespace":"ckad-job"},"spec":{"jobTemplate":{"metadata":{"creationTimestamp":null,"name":"learning-every-minute"},"spec":{"template":{"metadata":{"creationTimestamp":null},"spec":{"containers":[{"command":["/bin/sh","-c","echo 'I am practicing for CKAD certification'"],"image":"busybox:1.28","name":"learning-every-minute","resources":{}}],"restartPolicy":"OnFailure"}}}},"schedule":"*/1 * * * *"},"status":{}}
creationTimestamp: "2024-01-10T19:24:32Z"
generation: 2
name: learning-every-minute
namespace: ckad-job
resourceVersion: "5456"
uid: 93bf7d9f-dd87-4426-881f-728db0eb2213
spec:
concurrencyPolicy: Allow
failedJobsHistoryLimit: 1
jobTemplate:
metadata:
creationTimestamp: null
name: learning-every-minute
spec:
template:
metadata:
creationTimestamp: null
spec:
containers:
- command:
- /bin/sh
- -c
- echo I am practicing for CKAD certification
image: busybox:1.28
imagePullPolicy: IfNotPresent
name: learning-every-minute
resources: {}
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
dnsPolicy: ClusterFirst
restartPolicy: OnFailure
schedulerName: default-scheduler
securityContext: {}
terminationGracePeriodSeconds: 30
schedule: '*/1 * * * *'
successfulJobsHistoryLimit: 3
suspend: false
status:
lastScheduleTime: "2024-01-10T20:31:00Z"
lastSuccessfulTime: "2024-01-10T20:31:05Z"
However, correct answer is :
apiVersion: batch/v1
kind: CronJob
metadata:
namespace: ckad-job
name: learning-every-minute
spec:
schedule: "* * * * *"
jobTemplate:
spec:
template:
spec:
containers:
- name: learning-every-minute
image: busybox:1.28
imagePullPolicy: IfNotPresent
command:
- /bin/sh
- -c
- echo I am practicing for CKAD certification
restartPolicy: OnFailure
Can you please help me to know how every minute schedule is incorrect here in my answer.