Kubernetes CronJob — Scheduled Tasks
Create Kubernetes CronJobs for scheduled tasks with history limits, concurrency control, and deadlines.
apiVersion: batch/v1
kind: CronJob
metadata:
name: daily-report
namespace: production
spec:
schedule: '0 6 * * *' # 6 AM UTC daily
timeZone: 'America/New_York'
concurrencyPolicy: Forbid # skip if previous still running
successfulJobsHistoryLimit: 3
failedJobsHistoryLimit: 5
startingDeadlineSeconds: 300 # skip if 5min late
jobTemplate:
spec:
backoffLimit: 2
activeDeadlineSeconds: 3600 # kill if runs > 1hr
template:
spec:
restartPolicy: OnFailure
containers:
- name: report-generator
image: myapp/report-gen:latest
command: ['python', 'generate_report.py']
env:
- name: DB_URL
valueFrom:
secretKeyRef:
name: db-credentials
key: url
resources:
requests:
cpu: 200m
memory: 256Mi
limits:
cpu: '1'
memory: 1GiSponsored
DigitalOcean
Use Cases
- Scheduling daily data exports or reports
- Running cleanup tasks on a cron schedule
- Database maintenance jobs in Kubernetes
Tags
Related Snippets
Similar patterns you can reuse in the same workflow.
Kubernetes Deployment Manifest
Production-ready Kubernetes deployment with resource limits, probes, rolling updates, and anti-affinity.
Best for: Deploying containerized applications to Kubernetes
Kubernetes HPA — Horizontal Pod Autoscaler
Configure horizontal pod autoscaling based on CPU, memory, and custom metrics for Kubernetes workloads.
Best for: Auto-scaling APIs based on traffic load
Kubernetes ConfigMap and Secret Management
Create and use ConfigMaps and Secrets for application configuration with env vars and volume mounts.
Best for: Managing application configuration in Kubernetes
Kubectl Rollout — Restart, Status, and Undo
Essential kubectl rollout commands for deployments: restart, status checks, history, and rollback.
Best for: Zero-downtime deployment restarts