Interview Prep/Python for DevOps/Kubernetes, Docker, SSH & fleet automation

A Kubernetes CronJob running a Python script sometimes runs twice at the same time. How do you fix it?

IntermediateScenarioKubernetes, Docker, SSH & fleet automation
Answer

Situation read → Concurrency policy, or a run that exceeds the schedule interval.

What I'd do →

  1. Set concurrencyPolicy: Forbid on the CronJob.
  2. Set startingDeadlineSeconds so missed runs do not pile up.
  3. Make the script idempotent anyway; Kubernetes CronJobs can, in rare cases, create two jobs.
  4. Add an activeDeadlineSeconds so a hung run is killed.

Why → Forbid plus idempotency covers both the common and rare double runs.

Interview tip → Mention that CronJobs are "at least once", not "exactly once".

All Python for DevOps questions Roadmap: Python for automation

More on Kubernetes, Docker, SSH & fleet automation