• Home
  • Google Cloud
  • Scale your own way, using HPA with built-in support for PromQL metrics queries in GKE

Earlier this year, we announced native support for Google Kubernetes Engine (GKE) custom metrics. This milestone allowed you to scrap external adapters and instead collect autoscaling metrics directly from your pods. By routing these metrics straight to the Horizontal Pod Autoscaler (HPA), we cut metrics reading latency down to 5 seconds.

Today, we are excited to introduce built-in support for processing Prometheus metrics, allowing you to use expressive PromQL queries to customize autoscaling triggers. With this update, HPA can now directly process autoscaling metrics present in Cloud Monitoring using Google Managed Service for Prometheus. Reading metrics from these backends will not require third-party adapters, leveraging the AutoscalingMetric integration used to support pod-level metrics. After the preview, we plan to support self-hosted Prometheus servers as we move to general availability. 

The challenge: Setting up Cloud Monitoring metrics

Support for custom pod-level metrics made autoscaling more straightforward, but production workloads often need to scale on multiple, complex infrastructure metrics. Common examples include scaling:

  • a worker pool based on the number of unacknowledged messages in a Pub/Sub topic

  • an inference service based on query-per-second (QPS) metrics stored in Cloud Monitoring / Prometheus

  • a webserver farm based on the 95th percentile of their measured response time

To achieve this, you used to need to deploy an external adapter like the Stackdriver Custom Metrics Adapter or the Prometheus adapter to retrieve the metrics from an external logging environment. While this sounds straightforward at first, these adapters introduce a lot of operational friction:

  • Management overhead: Platform teams have to install, configure, patch, and monitor these third-party components.

  • Reliability and inefficiency: Intermediate adapter pods reading from external systems introduce failure points in critical autoscaling loops. 

  • IAM complexity: Enabling secure cross-component communication requires setting up Kubernetes service account mappings to Cloud service accounts including their permissions.

And while setting up this system and maintaining it not impossible, it’s complex and features a complicated architecture:

1

How processing Prometheus Metrics in GKE can help

Extending the AutoscalingMetric object drastically simplifies this setup. Now you can read metrics from monitoring directly via PromQL and provide them to HPA via a high-performance, low-latency autoscaling pipeline, resulting in a simplified environment.

2

To prevent inefficiencies, we built this feature with minimal resource consumption in mind. The controller runs on the GKE control plane. It monitors your AutoscalingMetric custom resources and only deploys the system pod on your user nodes when a PromQL metric is actively requested. If no Prometheus metrics are configured, the controller is shut down, so there’s no resource overhead.

Configuring built-in Prometheus metrics

Configuring GKE to use PromQLl metrics is easy; here’s a sample configuration file providing PubSubs message queue depth as scaling metric:

code_block
<ListValue: [StructValue([('code', 'apiVersion: autoscaling.gke.io/v1beta1rnkind: AutoscalingMetricrnmetadata:rn name: gmp-metricrnspec:rn metrics:rn – promql:rn name: pubsub-queue-depthrn query: |rn {rn "pubsub.googleapis.com/subscription/num_undelivered_messages",rn subscription_id="my-subscription"rn }'), ('language', ''), ('caption', )])]>

Linking Prometheus metrics to your HPA

Once defined in your AutoscalingMetric resource, you can reference the metric in your standard HorizontalPodAutoscaler using the same intuitive format as raw custom metrics: autoscaling.gke.io||.

Scaling globally (Prometheus metric)

For global metrics like a queue size that returns a single aggregate value:

code_block
<ListValue: [StructValue([('code', 'apiVersion: autoscaling/v2rnkind: HorizontalPodAutoscalerrnmetadata:rn name: worker-hparnspec:rn scaleTargetRef:rn apiVersion: apps/v1rn kind: Deploymentrn name: worker-deploymentrn maxReplicas: 10rn metrics:rn – type: Externalrn external:rn metric:rn name: autoscaling.gke.io|gmp-metric|pubsub-queue-depthrn target:rn type: AverageValuern averageValue: 100 # maintain queue size at ~100 per pod'), ('language', ''), ('caption', )])]>

Scaling on Cloud Monitoring per-Pod metrics

GKE natively supports scale based on the most recent gauge metric values, but PromQL offers greater flexibility, allowing you to scale across time windows and calculate rates or histogram percentiles.

To use this capability, configure your PromQL metric to include a label for the pod name, then assign type: Pods within your AutoscalingMetric manifest. Below is an example that calculates a Pod’s average memory usage over a five-minute rolling window.

code_block
<ListValue: [StructValue([('code', 'apiVersion: autoscaling.gke.io/v1beta1rnkind: AutoscalingMetricrnmetadata:rn name: per-pod-stored-metricrnspec:rn metrics:rn – promql:rn name: container-memory-metricrn query: |rn sum by ("pod")rn (avg_over_time({"container_memory_working_set_bytes"}[5m]))rn type: Pods # The promql query returns per-pod metrics'), ('language', ''), ('caption', )])]>

Key benefits

  • No adapter maintenance: No pods to install, configure, or upgrade. The entire lifecycle is fully managed within GKE.

  • Streamlined security: Out of the box, the Kubernetes Default Node Service Agent has read permissions to Cloud Monitoring and Google Managed Prometheus in the same project. No extra IAM service accounts, keys, or federation parameters are required.

  • Low latency and fast scalability: The new Autoscaling Metric system polls the backend every 15 seconds, helping ensure fast scaling reactions.

  • Rich query capabilities: Leverage the full power of PromQL (including rate calculations, averages, and percentiles) to translate high-level business and user-experience objectives directly into scaling.

  • Support for the new HPA scale-to-zero capability: Utilize it for scaling workloads to zero replicas when demand hits zero (e.g., Pub/Sub queue size) and, more crucially, back up from zero replicas quickly using CapacityBuffers API.

Try it today 

By natively supporting both custom container metrics and Prometheus metrics, GKE now  offers a more robust, performant, and low-friction autoscaling experience. Built-in support for Prometheus Metrics is in preview now. To learn more about setting up your first AutoscalingMetric resource, check out the latest GKE autoscaling documentation.

Author: wp_admin - This post was originally published on this site
Share this post

Subscribe to our newsletter

Keep up with the latest blog posts by staying updated. No spamming: we promise.
By clicking Sign Up you’re confirming that you agree with our Terms and Conditions.

Related posts

New Educronix Product

Educronix Softphone

Free WebRTC desktop softphone for Windows and macOS. Connects directly to your PBX — voice and video calls, Call Waiting, DND, live call quality and more. Choose your edition and platform:

100% WebRTC — built on the JsSIP library.

Standard Edition
Call Center Edition
🎙 AI Assistant(voice)