# One-off Job and a scheduled CronJob.
apiVersion: batch/v1
kind: Job
metadata:
  name: db-migrate
  namespace: demo
spec:
  backoffLimit: 3                 # retries before the Job is marked failed
  activeDeadlineSeconds: 600
  ttlSecondsAfterFinished: 3600   # clean up an hour after completion
  template:
    spec:
      restartPolicy: Never        # Jobs need Never or OnFailure
      securityContext:
        runAsNonRoot: true
        runAsUser: 1000
        seccompProfile:
          type: RuntimeDefault
      containers:
        - name: migrate
          image: busybox:1.37
          command: ["sh", "-c", "echo running migrations && sleep 5"]
          securityContext:
            allowPrivilegeEscalation: false
            capabilities:
              drop: ["ALL"]
---
apiVersion: batch/v1
kind: CronJob
metadata:
  name: nightly-report
  namespace: demo
spec:
  schedule: "0 2 * * *"           # 02:00 every day
  timeZone: "Etc/UTC"
  concurrencyPolicy: Forbid       # skip a run if the previous one is still going
  startingDeadlineSeconds: 300
  successfulJobsHistoryLimit: 3
  failedJobsHistoryLimit: 1
  jobTemplate:
    spec:
      template:
        spec:
          restartPolicy: OnFailure
          securityContext:
            runAsNonRoot: true
            runAsUser: 1000
            seccompProfile:
              type: RuntimeDefault
          containers:
            - name: report
              image: busybox:1.37
              command: ["sh", "-c", "date; echo report done"]
              securityContext:
                allowPrivilegeEscalation: false
                capabilities:
                  drop: ["ALL"]
