CloudsArk
Builds Images and Deployments Openshift

OpenShift Jobs And Cronjobs

Learn practical openshift jobs and cronjobs with oc commands, OpenShift manifests, verification steps, common mistakes, and production-focused guidance.

OpenShift Jobs And Cronjobs

Introduction

Jobs run finite work once, while CronJobs run Jobs on a schedule. In OpenShift, check the spawned pods and events when a scheduled task does not complete.

Before You Start

Make sure you are in the correct project and know whether the application is driven by a Deployment, DeploymentConfig, BuildConfig, ImageStream, or external registry image.

Practical Examples

oc create job report-now --image=registry.access.redhat.com/ubi9/ubi -- /bin/bash -c "date; echo done" -n app
oc get jobs -n app
oc logs job/report-now -n app
oc get pods -n app --selector=job-name=report-now

Example output:

NAME         COMPLETIONS   DURATION   AGE
report-now   1/1           8s         20s

Example YAML

apiVersion: batch/v1
kind: CronJob
metadata:
  name: nightly-report
spec:
  schedule: "0 2 * * *"
  jobTemplate:
    spec:
      template:
        spec:
          restartPolicy: Never
          containers:
            - name: report
              image: registry.access.redhat.com/ubi9/ubi
              command: ["/bin/bash", "-c", "date; echo report complete"]

Verification

oc describe job report-now -n app
oc logs job/report-now -n app
oc get events -n app --sort-by=.lastTimestamp

Troubleshooting

Inspect the Job or CronJob, then check the pod it created, its logs, exit code, schedule, and recent events.

Common Mistakes

  • Debugging only the Job and ignoring its pod.
  • Using a CronJob schedule in the wrong timezone assumption.
  • Leaving failed Jobs without history limits.

Quick Checklist

  • Confirm the active project.
  • Inspect the exact object named in the error.
  • Read recent events.
  • Apply one focused fix.
  • Verify status after the change.

Summary

OpenShift Jobs And Cronjobs should be verified with commands that match the OpenShift object being changed or investigated.