<p>I'm running a fairly resource-intensive service on a Kubernetes cluster to support CI activities. Only a single replica is needed, but it uses a lot of resources (16 cpu), and it's only needed during work hours generally (weekdays, 8am-6pm roughly). My cluster runs in a cloud and is setup with instance autoscaling, so if this service is scaled to zero, that instance can be terminated.</p>

<p>The service is third-party code that cannot be modified (well, not easily). It's a fairly typical HTTP service other than that its work is fairly CPU intensive.</p>

<p>What options exist to automatically scale this Deployment down to zero when idle?</p>

<p>I'd rather not setup a schedule to scale it up/down during working hours because occasionally CI activities are performed outside of the normal hours. I'd like the scaling to be dynamic (for example, scale to zero when idle for >30 minutes, or scale to one when an incoming connection arrives).</p>

Patrick
<p>Actually Kubernetes supports the scaling to zero only by means of an API call, since the Horizontal Pod Autoscaler does support scaling down to 1 replica only.</p>

<p>Anyway there are a few Operator which allow you to overtake that limitation by intercepting the requests coming to your pods or by inspecting some metrics.</p>

<p>You can take a look at  <a href="https://knative.dev/" rel="noreferrer">Knative</a> or <a href="https://keda.sh/" rel="noreferrer">Keda</a>.
They enable your application to be serverless and they do so in different ways.</p>

<p><strong>Knative</strong>, by means of Istio intercept the requests and if there's an active pod serving them, it redirects the incoming request to that one, otherwise it trigger a scaling.</p>

<p>By contrast, <strong>Keda</strong> best fits event-driven architecture, because it is able to inspect predefined metrics, such as lag, queue lenght or custom metrics (collected from Prometheus, for example) and trigger the scaling.</p>

<p>Both support scale to zero in case predefined conditions are met in a equally predefined window.</p>

<p>Hope it helped.</p>
