I have an application with different endpoints (rest services) which runs in a docker container in kubernetes pods.
These endpoints are reachable like:
localhost:8080/myapp/status/health
or
localhost:8080/myapp/status/version
I would like to add some of these endpoints (like health and version) to the prometheus metrics. Do I need to write an exporter or which exporters are recommended to use in this senario?
It sounds like you are looking for key words and a place to start to configure where Prometheus, running in Kubernetes cluster, could scrape the data from a metrics end point.
I suggest to add the job_name for the two paths myapp/status/version
and myapp/status/health
to your prometheus Configmap scrape_config section and make the target what ever the app name is called based on the kube-dns assignment. The actual domain name is most likely the app_name appended to the namespace it is in: <app_name>.<k8s_namespace>.svc.cluster.local>
Localhost usually only resolves on your immediate system (i.e. laptop or the pod itself) and it is tied to 127.0.0.1 which is not normally routed within a network by kube-dns, as all the pods & nodes technically have that interface and there is no way to differentiate between them.
You can verify that the FQDN resolves by getting into the K8s pod and issuing a nslookup on the combination. The FQDN won't resolve outside of the cluster as it is meant to be routable within the cluster -- unless you build it otherwise.
HTH and good luck with the configuration.
I think that the best approach here would be to scrape the application itself rather than metrics from Kubernetes itself.
You'll need to instrument your application with a Prometheus client library to export the metrics about those endpoints you're interested in and configure Prometheus to scrape the application.