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

ServiceMonitor is selected but its targets don't appear on `/targets`

IntermediateTroubleshootingKubernetes monitoring and the Prometheus Operator
Answer

Likely causes → spec.selector does not match the Service's labels (not the pod labels), endpoints[].port refers to a port name that the Service doesn't define, or namespaceSelector is missing for a cross-namespace Service.

Diagnose →

kubectl get svc -n shop checkout --show-labels
kubectl get svc -n shop checkout -o jsonpath='{.spec.ports[*].name}'
kubectl get endpoints -n shop checkout

Fix → Match Service labels, use the named port (port: http-metrics) or targetPort, and add namespaceSelector: { matchNames: [shop] } if needed.

Prevent → Name metrics ports consistently (metrics).

All Monitoring & Observability questions Roadmap: Monitoring & alerting

More on Kubernetes monitoring and the Prometheus Operator