<p>I have set up prom-client (unofficial client library for prometheus) to collect custom metrics what I need.
I have prometheus server deployed from helm following this <a href="https://eksworkshop.com/intermediate/240_monitoring/deploy-prometheus/" rel="nofollow noreferrer">eks setup guide</a>. Now I am trying to edit default configmap to collect my app metrics as well, but getting error </p>

<p><code>parsing YAML file /etc/config/prometheus.yml: yaml: unmarshal errors:\n  line 22: field cluster_ip not found in type kubernetes.plain\n  line 25: cannot unmarshal !!str</code>default<code>into []string</code></p>

<p>This is what I have done as per docs
prometheus.yaml configmap file</p>

<pre><code>apiVersion: v1
data:
  alerting_rules.yml: |
    {}
  alerts: |
    {}
  prometheus.yml: |
    global:
      evaluation_interval: 1m
      scrape_interval: 1m
      scrape_timeout: 10s
    rule_files:
    - /etc/config/recording_rules.yml
    - /etc/config/alerting_rules.yml
    - /etc/config/rules
    - /etc/config/alerts
    scrape_configs:
    ...DEFAULT CONFIGS...
    - job_name: my_metrics
      scrape_interval: 5m
      scrape_timeout: 10s
      honor_labels: true
      metrics_path: /api/metrics
      kubernetes_sd_configs:
        - role: service
          cluster_ip: 10.100.200.92
          namespaces:
            names:
              default
  recording_rules.yml: |
    {}
  rules: |
    {}
kind: ConfigMap
metadata:
  creationTimestamp: "2020-06-08T09:26:38Z"
  labels:
    app: prometheus
    chart: prometheus-11.3.0
    component: server
    heritage: Helm
    release: prometheus
  name: prometheus-server
  namespace: prometheus
  uid: 8fadb17a-f5c5-4f9d-a931-fa1f77684847
</code></pre>

<p>Here clusterIP is the IP assigned for my service to expose deployment.</p>

<p>My deployment.yaml file</p>

<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: myapp
spec:
  replicas: 2
  strategy:
    type: RollingUpdate
  selector:
    matchLabels:
      name: myapp
  template:
    metadata:
      labels:
        name: myapp
    spec:
      containers:
        - image: IMAGE_URL:BUILD_NUMBER
          name: myapp
          resources:
              limits:
                cpu: "1000m"
                memory: "2400Mi"
              requests:
                cpu: "500m"
                memory: "2000Mi"
          imagePullPolicy: IfNotPresent
          ports:
              - containerPort: 5000
                name: myapp
</code></pre>

<p>My service.yaml file which is exposing deployment</p>

<pre><code>apiVersion: v1
kind: Service
metadata:
  name: myapp
spec:
  selector:
    deploy: staging
    name: myapp
  type: ClusterIP
  ports:
    - port: 80
      targetPort: 5000
      protocol: TCP
</code></pre>

<p>Is there some different/efficient way to target my app for metrics collection, please let me know. Thanks</p>

warl0ck
<p>This is what I am using to enable prometheus scraping inside the cluster.</p>
<p>In the scrape config, I have this snippet:</p>
<pre><code>      - job_name: 'kubernetes-pods'
        kubernetes_sd_configs:
          - role: pod
        relabel_configs:
          - source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_scrape]
            action: keep
            regex: true
          - source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_path]
            action: replace
            target_label: __metrics_path__
            regex: (.+)
          - source_labels: [__address__, __meta_kubernetes_pod_annotation_prometheus_io_port]
            action: replace
            regex: ([^:]+)(?::\d+)?;(\d+)
            replacement: $1:$2
            target_label: __address__
          - action: labelmap
            regex: __meta_kubernetes_pod_label_(.+)
          - source_labels: [__meta_kubernetes_namespace]
            action: replace
            target_label: kubernetes_namespace
          - action: labeldrop
            regex: '(kubernetes_pod|app_kubernetes_io_instance|app_kubernetes_io_name|instance)'

</code></pre>
<p>This is taken directly from the default values for the prometheus helm chart: <a href="https://github.com/helm/charts/blob/master/stable/prometheus/values.yaml#L1452" rel="nofollow noreferrer">https://github.com/helm/charts/blob/master/stable/prometheus/values.yaml#L1452</a></p>
<p>What that does, is instruct prometheus to scrape every pod that has the annotation:
<code>prometheus.io/scrape: &quot;true&quot;</code>
set. With these annotations on the <em>pod</em> you can then configure the port and path of the scrape:</p>
<pre><code>prometheus.io/path: &quot;/metrics&quot;
prometheus.io/port: &quot;9090&quot;
</code></pre>
<p>So, you would need to modify your <code>deployment.yaml</code> to specify these annotations as well:</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: myapp
spec:
  replicas: 2
  strategy:
    type: RollingUpdate
  selector:
    matchLabels:
      name: myapp
  template:
    metadata:
      labels:
        name: myapp
    annotations:
      prometheus.io/scrape: &quot;true&quot;
      prometheus.io/port: &quot;&lt;enter port of pod to scrape&gt;&quot;
      prometheus.io/path: &quot;&lt;enter path to scrape&gt;&quot;
    spec:
      containers:
        - image: IMAGE_URL:BUILD_NUMBER
...
</code></pre>
