Question: How does k8s manage pod creation/deletion in cronjobs and how to specify memory/cpu requirements in CronJob?

my question is -
How does k8s manage pod creation/deletion in cronjobs and how to specify memory/cpu requirements in a Kubernetes CronJob ?

Cluster information:

Kubernetes version: n/a
Cloud being used: n/a
Installation method:
Host OS: linux
CNI and version:
CRI and version:

Please take a look at kubernetes documentation for more details.

The Kubernetes controller watches for CronJob resources and schedules Jobs based on the defined schedule (.spec.schedule field in crontab format).

  • The Job creates one or more Pods to run the specified workload.

  • If .spec.concurrencyPolicy is set to:

  • Allow (default) → Multiple instances can run concurrently.

  • Forbid → A new Job won’t start if a previous Job is still running.

  • Replace → A new Job replaces an existing one.

  • The Pod executes the specified container command.

  • If the Pod completes successfully (Exit Code 0), the Job is marked as successful.

  • If the Pod fails, Kubernetes may retry it based on .spec.backoffLimit.

Example for CPU, memory config

apiVersion: batch/v1
kind: CronJob
metadata:
  name: my-cronjob
spec:
  schedule: "0 * * * *"  # Runs every hour
  jobTemplate:
    spec:
      template:
        spec:
          containers:
          - name: my-container
            image: my-image:latest
            resources:
              requests:
                cpu: "500m"         # Requests 0.5 CPU
                memory: "256Mi"     # Requests 256MB of RAM
              limits:
                cpu: "1"            # Limits to 1 CPU
                memory: "512Mi"     # Limits to 512MB of RAM
          restartPolicy: OnFailure  # Restart on failure

1 Like