We are using AKS v1.26.6. Our deployed code is .Net Core 6/7 based.
We created a cronjob and deployed in AKS. This job runs at fixed schedule in evening. All is good so far, now we need to know IF this job execution was success, i mean we need an event notification so we can further work based on that event notification.
Does this feature out of box available for AKS Cron jobs?
AKS Cron jobs don't have a built-in feature to send notifications upon completion. However, you can set up automated notifications using Azure Monitor. Azure Monitor can monitor your AKS cluster and send alerts based on specific event patterns. You can configure alerts to trigger based on the completion of your Cron job. To set up Azure Monitor to trigger alerts based on the completion of Kubernetes CronJobs in AKS, First, ensure that Azure Monitor for containers is enabled for your AKS cluster.
To enable monitoring during AKS creation:
az aks create \
--resource-group myResourceGroup \
--name myAKSCluster \
--generate-ssh-keys \
--enable-addons monitoring \
--workspace-resource-id <Log-Analytics-workspace-resource-id>
To enable monitoring on an existing AKS cluster:
az aks enable-addons \
--addons monitoring \
--name myAKSCluster \
--resource-group myResourceGroup \
--workspace-resource-id <Log-Analytics-workspace-resource-id>
Deploy a CronJob
example
apiVersion: batch/v1
kind: CronJob
metadata:
name: hello
spec:
schedule: "*/1 * * * *"
jobTemplate:
spec:
template:
spec:
containers:
- name: hello
image: busybox
args:
- /bin/sh
- -c
- date; echo Hello from the Kubernetes cluster
restartPolicy: OnFailure
Create KQL Query for CronJob Completion Events
KubeEvents
| where TimeGenerated > ago(1d)
| where Namespace == "default" and Name contains "hello"
| where Reason == "SuccessfulCreate"
| project TimeGenerated, Name, Message
With the query ready, you can set up an alert in Azure Monitor:
References: