Do not restart cron on failure in kubernetes

You have to set:

backoffLimit: 0 

restartPolicy: Never 

concurrencyPolicy: Forbid.

backoffLimit means the number of times it will try before it is considered failed. The default is 6.

concurrencyPolicy set to Forbid means it will run 0 or 1 times, but not more.

restartPolicy set to Never means it won’t restart on failure.

You need to do all 3 of these things, or your cronjob may run more than once.

If a namespace is stuck in terminating stage

Please do not remove the finalizer, it is there for a reason. Try to instead find out which resources in the NS are pending deletion by:

  • Checking if any apiservice is unavailable and hence doesn’t serve its resources: kubectl get apiservice|grep False
  • Finding all resources that still exist via kubectl api-resources –verbs=list –namespaced -o name | xargs -n 1 kubectl get -n $your-ns-to-delete 
  • The solution to this problem is not to short-circuit the cleanup mechanism, its to find out what prevents cleanup from succeeding.