Creating a CronJob in Kubernetes:

In Kubernetes, a cron job is a type of Kubernetes resource that enables you to run a job on a scheduled basis. It works by creating a Job object that runs on a recurring schedule, similar to a standard cron job as below.

Here's an example of how you can create a cron job in Kubernetes using YAML configuration:


apiVersion: batch/v1beta1
kind: CronJob
metadata:
  name: schedule-post-cronjob
spec:
  schedule: "*/10 * * * *"
  jobTemplate:
    spec:
      template:
        spec:
          containers:
          - name: schedule-post
            image: ENTER_YOUR_DOCKER_IMA
            command: ["YOUR-COMMAD"]
          restartPolicy: OnFailure

Once you create this YAML configuration, you can apply it to your Kubernetes cluster using the kubectl apply command. The CronJob will then be created, and your job will start running on a scheduled basis according to the schedule you specified.

Disabling CronJob in Kubernetes:

If you want to disabling the particular CronJob, can do using the kubectl command below, you have to update/replace the cronjob name <job-name>
kubectl patch cronjobs <job-name> -p '{"spec" : {"suspend" : true }}'

 
You can disable all the cronjobs in a single command 
kubectl get cronjobs | grep False | cut -d' ' -f 1 | xargs kubectl patch cronjobs -p '{"spec" : {"suspend" : true }}'

If you want to view the status, just execute the command below,

kubectl get jobs