I have a cronjob running every couple of minutes in kubernetes and would like to set up an alert that notifies me when the cronjob stops working.
I'm expecting it to fail sometimes, it's calling two REST endpoints and they won't always be available.
I want to know if the last successful run happened more than x minutes ago. For this I need the last successful completion timestamp.
I'd like to use the kubectl
command line tool. How do I do this?
It was easier than I thought, this is my solution using
kubectl
andjq
:kubectl
fetches all job executions of the cronjob and prints them to json.jq
then selects all successful jobs and prints their completion-time.sort
andhead
then select the latest timestamp.