<p>I have a small Web Application running on a Google Kubernetes Cluster. But I want to save some money, because the web app does not get much traffic.</p>

<p>Thus my goal is to <strong>automatically</strong> downscale my Kubernetes cluster to 0 nodes if there was no traffic for more than some amount of time. And of course it should automatically spin up a node if there is incoming traffic.</p>

<p>Any ideas on how to do this?</p>

Florian Ludewig
<p>The GKE autoscaler scales up only when there are pods to be scheduled that do not fir on any current nodes and scaling up would allow the pod to be scheduled.</p>

<p>Scaling down occurs whenever a node is using less than half it's total memory and CPU, and all the pods running on the node can be scheduled on another node.</p>

<p>This being said, the autoscaler will never scale a cluster down to 0 as the reuirements for that can't be met. </p>

<p>However, you can configure <a href="https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale/" rel="nofollow noreferrer">Horizontal Pod Autoscaling</a> for your application deployment. You can configure HPA to scale up or down based on the <a href="https://stackoverflow.com/questions/60217475/autoscale-pods-based-on-http-request-count/60217825#60217825">number of HTTP requests using a custom metric</a>. Despite this, HPA should also not scale the deployment all the way down to 0, nor should it scale up from 0.</p>

<p>If you configure HPA properly, enable cluster autoscaling, and plan how your pods are being deployed by leveraging <a href="https://stackoverflow.com/a/58142927/9231144">taints, tolerations, and affinity</a>, then you can optimze autoscaling so that your cluster will scale down to a minimal size. But it still will not be 0.</p>

<p>All this being said, if you are running just a simple application with extended downtime, you may want to consider using Cloud Run or App Engine as those will be easier to manage than GKE and will have far less overhead (and likely less cost).</p>
