• you can create Jobs to run number of task inside Pod
  • It run instantly and completes

Run Periodically or At Schedule Time

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
 
  • The .spec.schedule field is required. The value of that field follows the Cron syntax
  • The .spec.jobTemplate defines a template for the Job that CronJob creates.
  • The .spec.jobTemplate.spec.template defines a template for actual Job

Commands

  1. Create a cronjob

kubectl create -f cronjob.yaml

  1. Check cronjob detail

kubectl get cronjob

  1. To delete the cronjob

kubectl delete cronjob <job-name>


⬅️ Jobs | ➡️

References

  1. https://kubernetes.io/docs/concepts/workloads/controllers/cron-jobs/