I have created kubernetes cron job to perform a scheduled task and it runs periodically at the scheduled time. But it also runs when the node pools are scaled up.
Node pools are scaled down one by one everyday night and scaled up in the morning. Auto scaling is disabled when scaling down and enabled when scaling up. When scaling up, cron job runs and executes the scheduled task which is not scheduled at that time.
cron yaml -
apiVersion: batch/v1
kind: CronJob
metadata:
name: app-cron
labels:
run: app-cron
spec:
schedule: "1 0 * * *"
concurrencyPolicy: Forbid
successfulJobsHistoryLimit: 0
failedJobsHistoryLimit: 1
jobTemplate:
spec:
backoffLimit: 3
template:
spec:
containers:
- name: app-cron
image: curlimages/curl
command: [ "curl", "$(SERVICE_HOST_KEY)" ]
env:
- name: SERVICE_HOST_KEY
valueFrom:
configMapKeyRef:
name: cron-config
key: SERVICE_HOST
restartPolicy: OnFailure
How can I stop running cron at the node pool scaling up time ?