<p>I am trying to expose some custom metrics of a kubernetes application  at prometheus.</p>
<p>I successfully deploy deploy my app at kubernetes. The ServiceMonitor is also added but no targets are discovered (0/0 up) .
The application is an nginx server with the relevant nginx-prometheus-exporter sidecar.</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-example-v3
  labels:
    app: nginx-example-v3
spec:
  selector:
    matchLabels:
      app: nginx-example-v3
  template:
    metadata:
      labels:
        app: nginx-example-v3
    spec:
      containers:
      - name: nginx
        image: nginx
        resources:
          limits:
            memory: &quot;128Mi&quot;
            cpu: &quot;100m&quot;
        ports:
        - name: http
          containerPort: 8080
        volumeMounts:
        - name: &quot;config&quot;
          mountPath: &quot;/etc/nginx/nginx.conf&quot;
          subPath: &quot;nginx.conf&quot;
      - name: exporter
        image: nginx/nginx-prometheus-exporter:0.8.0
        ports:
        - containerPort: 9113
      volumes:
        - name: &quot;config&quot;
          configMap:
            name: &quot;nginx-example-v2-config&quot;
            
---
apiVersion: v1
kind: Service
metadata:
  labels:
    name: nginx-example-v3
  name: nginx-example-v3
spec:
  type: LoadBalancer
  selector:
    app: nginx-example-v3
  ports:
  - name: http
    port: 8080
    targetPort: 8080
  - name: http-exporter
    port: 9113
    targetPort: 9113
</code></pre>
<p>After that i can see the nginx custom metrics exposed at the /metrics API:
<a href="https://i.stack.imgur.com/OfMav.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/OfMav.png" alt="enter image description here" /></a></p>
<p>Then i apply the monitoring service:</p>
<pre><code>apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
  name: nginx-example-v3
spec:
  endpoints:
  - bearerTokenFile: /var/run/secrets/kubernetes.io/serviceaccount/token
    interval: 15s
    port: web
  selector:
    matchLabels:
      app: nginx-example-v3
</code></pre>
<p>i can see that the service is successfully added at prometheus &quot;Service Discovery&quot; section:
<a href="https://i.stack.imgur.com/JL712.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/JL712.png" alt="enter image description here" /></a></p>
<p>BUT no targets are discovered (0/0 up) on behalf of prometheus
<a href="https://i.stack.imgur.com/6Hhz5.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/6Hhz5.png" alt="enter image description here" /></a></p>
<p>What i am missing???
Any help is really apreciated since i have been stuck on this many days!
Thank you very much in advance. :-)</p>
<p>Replies
@efotopoulou</p>

<p>I slightly changed the service manifest and i am able to get the metrics now.
sorry for the new discussion. i hope my manifests help other persons to configure their services.
This is the updated manifest.
:-)</p>
<pre><code>apiVersion: v1
kind: Service
metadata:
  labels:
    app: nginx-example-v3
  name: nginx-example-v3
spec:
  type: LoadBalancer
  selector:
    app: nginx-example-v3
  ports:
  - name: http
    port: 8080
    targetPort: 8080
  - name: web
    port: 9113
    targetPort: 9113
</code></pre>
