<p>Thanos requires a targetPort defined as a string in the Service for the ServiceMonitor to communicate with it.</p>
<p>However, just defining the targetPort as a string causes problems. I believe that something more is needed in the Deployment. I think the targetPort 'web' must be defined in the Deployment.</p>
<p>Can anyone assist with how the Deployment should look?</p>
<pre><code>apiVersion: v1
kind: Service
metadata:
  name: my-service
  labels:
    app: my-app
    tenant: a
    servicemonitor: my-servicemonitor
    monitor: &quot;true&quot;
spec:
  type: ClusterIP
  ports:
    - name: web
      port: 80
      protocol: TCP
      targetPort: web
  selector:
    app: my-app
---
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
  labels:
    app: my-app
    tenant: a
  name: my-monitor
spec:
  endpoints:
    - port: web
      path: /metrics
  namespaceSelector:
    matchNames:
      - my-namespace
  selector:
    matchLabels:
      servicemonitor: my-servicemonitor
      monitor: &quot;true&quot;
</code></pre>

Matthew S
<p>A simple example of defining the targetPort as string is to first define it in the Deployment before you can refer to it as a string in targetPort in a service. Below is the simple example to show how to map &quot;http&quot; ( port name) from deployment in a service targetPort spec.</p>
<p><strong>Deployment:</strong></p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: backend
spec:
  selector:
    matchLabels:
      app: hello
      tier: backend
      track: stable
  replicas: 3
  template:
    metadata:
      labels:
        app: hello
        tier: backend
        track: stable
    spec:
      containers:
        - name: hello
          image: &quot;gcr.io/google-samples/hello-go-gke:1.0&quot;
          ports:
            - name: http
              containerPort: 80
</code></pre>
<p><strong>Service:</strong></p>
<pre><code>apiVersion: v1
kind: Service
metadata:
  name: hello
spec:
  selector:
    app: hello
    tier: backend
  ports:
  - protocol: TCP
    port: 80
    targetPort: http
</code></pre>
