jthomperoo / custom-pod-autoscaler

Custom Pod Autoscaler program and base images, allows creation of Custom Pod Autoscalers

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Support scaling to zero

jjhuff opened this issue · comments

This code seems to be preventing me from scaling a deployment to zero replicas:

if currentReplicas == 0 {

My use case is a queue-based processing system with a bunch of GPUs, so scale to zero is rather important (and also why I can't use the build in HorizontalPodAutoscaler)

Ah OK, thanks for the feedback, helpful to hear a use case. So the way the current code works is if the current replica count is 0 scaling is disabled on the resource, so a resource can be scaled down to 0 replicas, but it cannot be scaled again after it has been set to 0. In your use case you need to be able to scale down to 0 and then afterwards scale upwards from 0 - is that right?

It seems reasonable to me, I think the way to do this would be to have a boolean configuration option allowScaleFromZero, if this is true you can scale upwards from 0, if it is false you can't scale upwards from 0 - would that be suitable for you? If so I'll add in that flag and get it in a new release (v0.12.0), thanks for finding that!

Yup, that's exactly right. I'm curious about the use case of 0 being disabled? Seems like a label on the deployment might be cleaner to mark it as 'autoscale disabled' might be cleaner?

Hmm that's a good point, I'm not sure if there actually is a use case for disabling autoscaling, I was basing it off the Horizontal Pod Autoscaler's behaviour:

https://github.com/kubernetes/kubernetes/blob/57108f6c3ea285284ef693be6d86d4bbd1d8a143/pkg/controller/podautoscaler/horizontal.go#L602-L607

But I think I implemented this incorrectly, autoscaling here is only disabled if minReplicas is > 0 so behaviour should be the same as you have laid out, if minReplicas is set to 0 scaling down to and up from 0 should be allowed - I think this is better.

I think the HPA behavior might have changed when they added the ability to scale to zero.
Thanks!

This is now available in version v0.12.0, there's an example here and some documentation here.

Hope that helps with your use case!