<p>We currently have a GKE environemt with several HPAs for different deployments. All of them work just fine out-of-the-box, but sometimes our users still experience some delay during peak hours.</p>
<p>Usually this delay is the time it takes the new instances to start and become ready.</p>
<p>What I'd like is a way to have an HPA that could predict usage and scale eagerly before it is needed.</p>
<p>The simplest implementation I could think of is just an HPA that could take the average usage of previous days and in advance (say 10 minutos earliers) scale up or down based on the historic usage for the current time-frame.</p>
<p>Is there anything like that in vanilla k8s or GKE? I was unable to find anything like that in GCP's docs.</p>

Diego
<p>If you want to scale your applications based on events/custom metrics, you can use <a href="https://keda.sh/" rel="nofollow noreferrer">KEDA</a> (Kubernetes-based Event Driven Autoscaler) which support scaling based on GCP Stackdriver, Datadog or Promtheus metrics (and many other scalers).</p>
<p>What you need to do is creating some queries to get the CPU usage at the moment: <code>CURRENT_TIMESTAMP - 23H50M</code> (or the aggregated value for the last week), then defining some thresholds to scale up/down your application.</p>
<p>If you have trouble doing this with your monitoring tool, you can create a custom metrics API that queries the monitoring API and aggregate the values (with the time shift) before sending it to the <a href="https://keda.sh/docs/2.7/scalers/metrics-api/" rel="nofollow noreferrer">metrics-api scaler</a>.</p>
