CronHPA is an operator to update HPA resources based on schedules. For example, you can decrease min replicas in the night-time and increase it in the day-time.
Here's a CronHPA example.
apiVersion: cron-hpa.dtaniwaki.github.com/v1alpha1
kind: CronHorizontalPodAutoscaler
metadata:
name: cron-hpa-example
spec:
template:
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: cron-hpa-nginx
minReplicas: 3
maxReplicas: 10
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 50
scheduledPatches:
- name: daytime
schedule: "0 8 * * *"
timezone: "Asia/Tokyo"
- name: nighttime
schedule: "0 22 * * *"
timezone: "Asia/Tokyo"
patch:
minReplicas: 1 # Less minimum replicas.
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 70 # More conservative scaling.Mark the target HPA resource as below to temporarily skip getting CronHPA's update.
apiVersion: autoscaling/v2beta2
kind: HorizontalPodAutoscaler
metadata:
annotations:
cron-hpa.dtaniwaki.github.com/skip: "true"
...Build and load the Docker image to your cluster.
$ make docker-build
# run a command to load the image to your cluster.If you use a kind cluster, there's a useful shortcut.
$ make kind-load
Install the CRD to the cluster.
$ make installDeploy a controller to the cluster.
$ make deployNow, deploy the samples.
$ make deploy-samplesYou will see sample HPA and deployment in the current context, maybe default depending on your env. The HPA resource gets updated periodically by the CronHPA.
- Fork it
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin my-new-feature) - Create new Pull Request
Copyright (c) 2021 Daisuke Taniwaki. See LICENSE for details.