Context: I'm relatively new to CronJobs and I have to "turn off" a GKE cluster during off hours (after 7pm/19h00 and until 9am/9h00) and during weekends (saturday and sunday, all day).
I followed this tutorial, got everything set up prety nice and lastly I edited the scheduled-autoscaler-example.yaml
file to have these cronjob expressions:
apiVersion: batch/v1
kind: CronJob
metadata:
name: scale-up
spec:
schedule: "* 9-18 * * 1-5" #every minute, 9h00 to 18h59, every week day
successfulJobsHistoryLimit: 0
failedJobsHistoryLimit: 1
jobTemplate:
spec:
template:
spec:
containers:
- name: custom-metric-exporter
image: <image...>
command:
- /export
- --name=scheduled_autoscaler_example
- --value=10
restartPolicy: OnFailure
backoffLimit: 1
---
apiVersion: batch/v1
kind: CronJob
metadata:
name: scale-down
spec:
schedule: "* 19-23,0-8 * * 1-5" #every minute, 19h00 to 23h59 then 00 to 8h59, every week day
successfulJobsHistoryLimit: 0
failedJobsHistoryLimit: 1
jobTemplate:
spec:
template:
spec:
containers:
- name: custom-metric-exporter
image: <image...>
command:
- /export
- --name=scheduled_autoscaler_example
- --value=0
restartPolicy: OnFailure
backoffLimit: 1
---
apiVersion: batch/v1
kind: CronJob
metadata:
name: scale-down-wknd
spec:
schedule: "* * * * 6,0" #weekends
successfulJobsHistoryLimit: 0
failedJobsHistoryLimit: 1
jobTemplate:
spec:
template:
spec:
containers:
- name: custom-metric-exporter
image: <image...>
command:
- /export
- --name=scheduled_autoscaler_example
- --value=0
restartPolicy: OnFailure
backoffLimit: 1
- One for scaling up during worktimes - from 9am to 7pm;
- One for scaling down at the end of the day - from 7pm to 9am the next morning;
- And one for scaling down during weekends.
The question: Assuming both cronjobs are gonna work as intended, is there a better expression or a simpler way of setting up the hour intervals for both the scaling up and down?