The Service Monitor Operator will create, destroy and update service monitor resources for you when you create, update or destroy a service.
The prometheus operator leverages Service Monitors
Custom Resrouces to define what services to monitor and details around how to scrape them. The goal of this project is to try and solve the most common service monitor configurations by automatically creating them for you based on annotations on your service.
The Service Monitor Operator will look at the following annotations on a service.
prometheus.io/probe:
- true or falseprometheus.io/port:
- TCP port listening for scrape requestsprometheus.io/path:
- path to metrics endpointprometheus.io/scheme:
- http or httpsprometheus.io/interval:
- scrape intervalprometheus.io/bearertoken:
path to bearer token file
These are all optional except for prometheus.io/probe
. If any values are omitted, the following are the default values that will be used
- port -
8080
- path -
/metrics
- scheme -
http
- scrapeInterval -
30s
- bearerTokenFile -
/var/run/secrets/kubernetes.io/serviceaccount/token
If the prometheus.io/probe:
annotation valuel is not set to true
it will ignore this service.
The path annotation is the path to the endpoint that will provide metrics. For example in the case of foo.bar.com/metrics
the path is /metrics
The Selectors for the servicemonitor
will be set to match the Labels
on the service and the Namespace
that the service is running in.
The following items are not yet implmented
- TargetLabels are not able to be changed
- PodTargetLabels are not able to be changed
- TLSConfig is not supported
kubectl apply -f deploy -n monitoring
- Requires operator-sdk from the operator framework
- To build an image for deployment/testing run the following
operator-sdk build <docker image name of your choosing>
- Update
deploy/operator.yaml
file with your image name - Deploy to cluster
kubectl apply -f deploy -n monitoring
You can also test without building and deploying to a cluster with the following command
operator-sdk up local --namespace=<your namespace> --kubeconfig=<path to your kubeconfig file>
You can ommit the kubeconfig
flag if you are using the default kubeconfig on your system ~/.kube/config
.