How to Suspend All Kubernetes CronJobs
Problem
CronJobs running on the cluster need to be (temporarily) suspended (such as for a maintenance activity).
Environment
- Platform9 Managed Kubernetes - All Versions
- kubectl
Procedure
- Export Kubeconfig.
- Retrieve a list of all CronJobs across all namespaces and patch their spec.
while read -r CRONJOB NAMESPACE; do kubectl -n $NAMESPACE patch cronjobs -p '{"spec" : {"suspend" : true }}' $CRONJOB; done <<< $(kubectl get cronjobs -Ao=jsonpath='{range .items[*]}{@.metadata.name}{" "}{@.metadata.namespace}{"\n"}{end}')
Was this page helpful?