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 →
- Set
concurrencyPolicy: Forbidon the CronJob. - Set
startingDeadlineSecondsso missed runs do not pile up. - Make the script idempotent anyway; Kubernetes CronJobs can, in rare cases, create two jobs.
- Add an
activeDeadlineSecondsso 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".
More on Kubernetes, Docker, SSH & fleet automation
You need a report of every pod in the cluster with no CPU or memory limits. How do you write it?BeginnerYou are asked to write a small operator-like script that adds a label to every new namespace. How do you approach it?AdvancedYou need to restart all Deployments in a namespace that reference a rotated Secret. How?AdvancedYour CI runners keep running out of disk because of Docker images. Write a cleanup plan in Python.IntermediateYou need to run `df -h` on 300 Linux hosts and list any above 85%. Python or Ansible?BeginnerA Python script SSHes to hosts with `AutoAddPolicy`. Security says that is unacceptable. What do you change?Intermediate