I'm using Google's managed collection on my GKE cluster (v1.24.26) and I can't find a way to collect metrics related to Kubernetes cronjobs. I can't find kube_cronjob_next_schedule_time, kube_job_status_failed nor kube_job_status_succeeded.
Do I need to configure something specific to gather this metrics on GKE?
I tried restarting kube-state-metrics-0, restarting the collectors, nothing worked.
                        
Ok, this threw me too.
I realized (belatedly) that
kube-state-metricscreates both aPodMonitoringandClusterPodMonitoring.The
PodMonitoringresource exposes metrics published by the Pod created bystatefulset.apps/kube-state-metricson the Pod'smetric-selfport (8081). TheClusterPodMonitoringexposes metrics published on the Pod'smetricport (8080) but this doesn't includecronjob-related metrics:You will need to add a regex for
kube_cronjobandkube_jobmetrics that you want in addition.One way (!) to do this after you've deployed Kube State Metrics, is to
kubectl patchtheclusterpodmonitoringresource.Of course, a better approach is to edit the Google-provided YAML (
kube-state-metrics.yaml#L324) before you Install Kube State Metrics.NOTE This (
VALUE) includes 2 changes:kube_cronjob_*metricskube_job_*metrics (removing the redundantkube_job_created_*metrics)You can demonstrate that the metrics are now scraped by Cloud Monitoring using metrics explorer and PromQL or native MQL (
prometheus.googleapis.com/kube_cronjob_next_schedule_time/gauge) or using APIs Explorer for Cloud Monitoring's Prometheus API:NOTE In this case I'd created a
CronJobcalledhellointestnamespace.