Skip to content

Jobs & CronJobs

A one-shot Job and a nightly CronJob that pass Kestrel’s admission rules. Commit them to the path your ArgoCD Application syncs (for example manifests/batch/) and replace <tenant>.

Before you start:

  • Create the namespace: kubectl create namespace <tenant>-batch.
  • Create the PVCs the manifests mount (input-data, output-data, tenant-data, report-output). See Persistent volumes.

What the manifests set, and why:

  • securityContext: the PodSecurity restricted fields that Kyverno enforces on every Pod. readOnlyRootFilesystem is optional hardening, which is why /tmp is an emptyDir.
  • fsGroup: a fresh Cinder volume is root:root 0755, so without it a non-root Pod gets Permission denied writing to the PVC.
  • priorityClassName: the Job uses uber-user-preempt-medium (preempts lower-priority Pods); the CronJob uses uber-user-significant (never preempts other Pods). See Priority classes.
  • resources: requests and limits count against your tenant’s quota. See Quotas.

The scripts are mounted from ConfigMaps, not baked into python:3.12-slim. Commit this next to the Job, and a report-script ConfigMap with a report.py key next to the CronJob.

manifests/batch/configmap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: process-script
namespace: <tenant>-batch
data:
process.py: |
# Replace with your real processing logic
from pathlib import Path
files = list(Path("/data/input").iterdir())
for f in files:
(Path("/data/output") / f.name).write_bytes(f.read_bytes())
print(f"processed {len(files)} files")
manifests/batch/job.yaml
apiVersion: batch/v1
kind: Job
metadata:
name: process-2026-q2 # change the name to run again
namespace: <tenant>-batch
spec:
backoffLimit: 1
activeDeadlineSeconds: 3600
template:
metadata:
labels:
job: process-2026-q2
spec:
restartPolicy: Never
priorityClassName: uber-user-preempt-medium
securityContext:
runAsNonRoot: true
runAsUser: 1000
fsGroup: 1000 # makes the Cinder PVC writable for UID 1000
fsGroupChangePolicy: OnRootMismatch
seccompProfile:
type: RuntimeDefault
containers:
- name: worker
image: python:3.12-slim
command: ['python', '/app/process.py']
securityContext:
allowPrivilegeEscalation: false
readOnlyRootFilesystem: true
capabilities:
drop: [ALL]
resources:
requests:
cpu: 500m
memory: 1Gi
limits:
cpu: 2
memory: 4Gi
volumeMounts:
- name: input
mountPath: /data/input
readOnly: true
- name: output
mountPath: /data/output
- name: tmp
mountPath: /tmp
- name: app
mountPath: /app
readOnly: true
volumes:
- name: input
persistentVolumeClaim:
claimName: input-data
- name: output
persistentVolumeClaim:
claimName: output-data
- name: tmp
emptyDir: {}
- name: app
configMap:
name: process-script

A Job’s Pod template is immutable, so editing a synced Job fails to sync. To run it again, change metadata.name and push. Don’t set ttlSecondsAfterFinished on a Job that ArgoCD manages: once the TTL deletes it, an Application with selfHeal recreates it and it runs again. Completed Pods don’t count against quota.

manifests/batch/cronjob.yaml
apiVersion: batch/v1
kind: CronJob
metadata:
name: nightly-report
namespace: <tenant>-batch
spec:
schedule: "0 3 * * *"
timeZone: "UTC" # or an IANA zone such as America/Vancouver
concurrencyPolicy: Forbid
successfulJobsHistoryLimit: 3
failedJobsHistoryLimit: 1
jobTemplate:
spec:
backoffLimit: 1
activeDeadlineSeconds: 1800
template:
spec:
restartPolicy: OnFailure
priorityClassName: uber-user-significant
securityContext:
runAsNonRoot: true
runAsUser: 1000
fsGroup: 1000 # makes the Cinder PVC writable for UID 1000
fsGroupChangePolicy: OnRootMismatch
seccompProfile:
type: RuntimeDefault
containers:
- name: reporter
image: python:3.12-slim
command: ['python', '/app/report.py']
securityContext:
allowPrivilegeEscalation: false
readOnlyRootFilesystem: true
capabilities:
drop: [ALL]
resources:
requests:
cpu: 250m
memory: 512Mi
limits:
cpu: 1
memory: 2Gi
volumeMounts:
- name: data
mountPath: /data/input
readOnly: true
- name: reports
mountPath: /data/reports
- name: tmp
mountPath: /tmp
- name: app
mountPath: /app
readOnly: true
volumes:
- name: data
persistentVolumeClaim:
claimName: tenant-data
- name: reports
persistentVolumeClaim:
claimName: report-output
- name: tmp
emptyDir: {}
- name: app
configMap:
name: report-script

Egress is unrestricted by default, so pulls from external stores work as is. If you add an egress NetworkPolicy, allow the destinations and DNS. See NetworkPolicy.

Terminal window
kubectl get jobs,pods -n <tenant>-batch
kubectl logs -n <tenant>-batch job/process-2026-q2
# Trigger the CronJob now instead of waiting for 03:00
kubectl create job nightly-report-manual --from=cronjob/nightly-report -n <tenant>-batch
kubectl logs -n <tenant>-batch job/nightly-report-manual -f

Start with kubectl describe job -n <tenant>-batch <job>: Pod creation errors appear in the Job’s events.

SymptomCause and fix
No Pods; Job events show a validate.kyverno.svc-fail PodSecurity denialA required securityContext field is missing. Restore it from the manifest above.
Pod Pending with Insufficient cpu or Insufficient memoryNo node has room. This is node capacity, not quota. uber-user-preempt-medium preempts only lower-priority Pods (uber-user-significant, and Pods with no class at priority 0); if there are none, the Pod waits.
ContainerCreating with FailedMount ... configmap "process-script" not foundCommit the script ConfigMap to the same path.
ContainerCreating with Multi-Attach errorA Pod on another node still has the ReadWriteOnce claim attached. See Storage classes.
Permission denied writing to /data/outputfsGroup is missing from the Pod securityContext.
External endpoint times outAn egress NetworkPolicy selects the Pods without allowing the destination or DNS. See NetworkPolicy.
CronJob never runskubectl describe cronjob nightly-report -n <tenant>-batch shows Last Schedule Time. Check the schedule against timeZone.
Job shows OutOfSync with a field is immutable errorYou edited a synced Job. Rename it instead.

For other messages, see the Troubleshooting index.