# Metricbeat on Kubernetes does not work with conditions

**URL:** <https://discuss.elastic.co/t/metricbeat-on-kubernetes-does-not-work-with-conditions/303506>\
**Category:** Beats\
**Tags:** metricbeat\
**Created:** [April 28, 2022, 11:54am UTC](https://discuss.elastic.co/t/metricbeat-on-kubernetes-does-not-work-with-conditions/303506 "2022-04-28T11:54:09Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![melkamar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/melkamar/32/100785_2.png) [@melkamar](https://discuss.elastic.co/u/melkamar)\
**Post date:** [April 28, 2022, 11:54am UTC](https://discuss.elastic.co/t/metricbeat-on-kubernetes-does-not-work-with-conditions/303506/1 "2022-04-28T11:54:09Z")

</div>

Hi! I want to set up a metricbeat data collection for _some_ pods in my cluster. I already have a working filebeat configuration where I collect logs from certain pods based on autodiscover template conditions. But the same configuration does not work for metricbeat.

I took the YAML of the metricbeat setup from the [official site](https://raw.githubusercontent.com/elastic/beats/8.1/deploy/kubernetes/metricbeat-kubernetes.yaml). The relevant part that I edited is this:

```nohighlight
---
apiVersion: v1
kind: ConfigMap
metadata:
  name: metricbeat-daemonset-config
  namespace: kube-system
  labels:
    k8s-app: metricbeat
data:
  metricbeat.yml: |-
    metricbeat.autodiscover:
      providers:
        - type: kubernetes
          scope: cluster
          node: ${NODE_NAME}
          unique: true
          templates:
            - condition:
                equals:
                  kubernetes.labels.test: foo
              config:
                - module: kubernetes
                  hosts: ["kube-state-metrics:8080"]
                  period: 10s
                  add_metadata: true
                  metricsets:
                    - state_node
                    - state_deployment
                    - state_daemonset
                    - state_replicaset
                    - state_pod
                    - state_container
                    - state_job
                    - state_cronjob
                    - state_resourcequota
                    - state_statefulset
                    - state_service

```

But with this configuration, no metrics are collected _at all_. When I remove the `- condition` node, then metrics are collected but from all the pods in the cluster. When the metrics are collected, I can verify that there are in fact documents from metricbeat from a pod with `kubernetes.labels.test: foo`. I can filter on those fields and they do exist.

But when I change the config again to include the `- condition`, then the stream of documents stops, including from the pod with the correct label.

Is this a known issue or is there something wrong with my configuration? Thanks

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [May 26, 2022, 1:54pm UTC](https://discuss.elastic.co/t/metricbeat-on-kubernetes-does-not-work-with-conditions/303506/2 "2022-05-26T13:54:15Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
