<p>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.</p>
<p>I'm expecting it to fail sometimes, it's calling two REST endpoints and they won't always be available.</p>
<p>I want to know if the last successful run happened more than x minutes ago. For this I need the last successful completion timestamp.</p>
<p>I'd like to use the <code>kubectl</code> command line tool. How do I do this?</p>

fafl
<p>It was easier than I thought, this is my solution using <code>kubectl</code> and <code>jq</code>:</p>
<pre><code>kubectl get job -l component=&lt;cronjob&gt; -n &lt;namespace&gt; -o json | \
jq -r '.items[] | select(.status.succeeded) | .status.completionTime' | \
sort -r | head -n 1
</code></pre>
<p><code>kubectl</code> fetches all job executions of the cronjob and prints them to json.</p>
<p><code>jq</code> then selects all successful jobs and prints their completion-time.</p>
<p><code>sort</code> and <code>head</code> then select the latest timestamp.</p>
