Search code examples
pythonkubernetesmlrunnuclio

k8s/MLRun, issue with scale to zero


I would like to save sources (RAM and CPU) for real-time classification function and I used scale to zero in MLRun/K8s, but it did not work, see information from Grafana (I expected zero replicas after 2 minutes from last call):

enter image description here

I used this code with scale to zero after 2 minutes (idle-time duration):

fn.spec.replicas = 1
fn.spec.min_replicas = 0
fn.spec.max_replicas = 2

fn.set_config(key="spec.scaleToZero.scaleResources", value=[{"metricName":"nuclio_processor_handled_events_total",
                                                            "windowSize" : "2m",
                                                            "threshold" : 0}])
                                                        

Did you have the same issue?


Solution

  • I got it. It was simple mistake on my side, I have to remove only this part of code fn.spec.replicas = 1, see full valid code:

    fn.spec.min_replicas = 0
    fn.spec.max_replicas = 2
    
    fn.set_config(key="spec.scaleToZero.scaleResources", value=[{"metricName":"nuclio_processor_handled_events_total",
                                                                "windowSize" : "2m",
                                                                "threshold" : 0}])