Interview Prep/Monitoring & Observability/Kubernetes monitoring and the Prometheus Operator

A new ServiceMonitor is not picked up by the Prometheus Operator

IntermediateTroubleshootingKubernetes monitoring and the Prometheus Operator
Answer

Likely causes → The ServiceMonitor lacks the label matching serviceMonitorSelector (kube-prometheus-stack: release: <helm-release>), its namespace is not in serviceMonitorNamespaceSelector, or the CRD version differs.

Diagnose →

kubectl get prometheus -n monitoring -o jsonpath='{.items[0].spec.serviceMonitorSelector}{"\n"}{.items[0].spec.serviceMonitorNamespaceSelector}'
kubectl get servicemonitor -n shop checkout -o yaml | grep -A3 labels

Fix → Add the label (e.g. release: kube-prometheus-stack), or set the Helm values serviceMonitorSelectorNilUsesHelmValues: false so all ServiceMonitors are selected.

Prevent → Provide a ServiceMonitor template with the right labels to app teams.

All Monitoring & Observability questions Roadmap: Monitoring & alerting

More on Kubernetes monitoring and the Prometheus Operator