First, make sure it’s actually not showing up:
- Check
prometheus-operatorlogs to verify if there is something abnormal happening - Go to prometheus UI
/service-discoveryand check if your service is present there. If it is thenServiceMonitorwas picked up, the issue is with incorrectly selected port in endpoints field. - If your
ServiceMonitoris not registered in/service-discoverythen check what is the value ofserviceMonitorSelectorfield in your Prometheus object and adjustingServiceMonitorlabels accordingly. Value of {} selects all serviceMonitors. See bellow for command. - If you still don’t have
ServiceMonitorregistered, check a fieldserviceMonitorNamespaceSelectorto verify if prometheus should look for serviceMonitor in that namespace. Value of{}selects all namespaces. - If after waiting 15 minutes you still don’t have your
ServiceMonitorregistered, check RBAC.
You can easily check the values set for the serviceMonitorSelector in your Prometheus Deployment:
kubectl get prometheuses.monitoring.coreos.com --all-namespaces -o jsonpath="{.items[*].spec.serviceMonitorSelector}"
In some case, you might need to add something like:
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
labels:
...
release: prometheus-community