iTranslated by AI
Collecting GKE Workload Metrics with Google Managed Prometheus
Goal
This article explains how to collect metrics from workloads on GKE using Google Managed Prometheus.
Prerequisites
It is assumed that a workload that outputs metrics is already deployed on GKE.
Steps
Enable Google Managed Prometheus on GKE
In this case, we will manage GKE with Terraform.
Set monitoring_config.managed_prometheus.enabled = true in the google_container_cluster resource.
With this setting, the PodMonitoring CRD (podmonitorings.monitoring.googleapis.com) is added to GKE.
Confirm that Managed Prometheus is enabled on the UI as well.

Deploy PodMonitoring
To collect metrics with Google Managed Prometheus, you need to deploy a PodMonitoring resource as shown below.
apiVersion: monitoring.googleapis.com/v1alpha1
kind: PodMonitoring
metadata:
name: XXX
spec:
selector:
matchLabels:
app: XXX
endpoints:
- port: metrics
path: /metrics
interval: 1m
Specify labels for the target Pod in spec.selector.
In spec.endpoints, specify the port where the Pod is exporting metrics.
Check in Cloud Monitoring
You can check the metrics in the Metrics explorer of Cloud Monitoring.

Check pricing
Please check the following documentation for Google Managed Prometheus pricing.
It costs $0.06 per 1 million samples.
The SKU is A4E4-DF03-CDB6.

Discussion