# Does K8s autodiscover work for all namespaces?

**URL:** https://discuss.elastic.co/t/does-k8s-autodiscover-work-for-all-namespaces/221874
**Category:** Beats
**Tags:** metricbeat
**Created:** [March 3, 2020, 11:31am UTC](https://discuss.elastic.co/t/does-k8s-autodiscover-work-for-all-namespaces/221874 "2020-03-03T11:31:42Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![ben.sharp](https://avatars.discourse-cdn.com/v4/letter/b/f08c70/32.png) [@ben.sharp](https://discuss.elastic.co/u/ben.sharp)
#### Post date: [March 3, 2020, 11:31am UTC](https://discuss.elastic.co/t/does-k8s-autodiscover-work-for-all-namespaces/221874/1 "2020-03-03T11:31:42Z")

</div>

Hello,

As the title says I was wondering whether hint-based autodiscover for K8s ([following this documentation](https://www.elastic.co/guide/en/beats/metricbeat/current/configuration-autodiscover-hints.html)) searches through all namespaces by default?

I have a metricbeat Daemonset running in the kube-system namespace, and am trying to scrape application logs using the following annotations:

```auto
co.elastic.metrics/module: prometheus
co.elastic.metrics/metricsets: collector
co.elastic.metrics/hosts: '${data.host}:8080'
co.elastic.metrics/period: 10

```

Metricbeat is able to ship the K8s cluster metrics but doesn't seem to be shipping the application metrics, which Prometheus running on its own is able to scrape.

---

<div class="post-metadata">

### Author: ![jsoriano](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jsoriano/32/27920_2.png) [@jsoriano](https://discuss.elastic.co/u/jsoriano)
#### Post date: [March 3, 2020, 6:50pm UTC](https://discuss.elastic.co/t/does-k8s-autodiscover-work-for-all-namespaces/221874/2 "2020-03-03T18:50:02Z")

</div>

Hi @ben.sharp,

Yes, autodiscover watches all namespaces by default.

Could you share the autodiscover configuration of your Metricbeat?  
Could you also check if Metricbeat is logging any error?

---

<div class="post-metadata">

### Author: ![ben.sharp](https://avatars.discourse-cdn.com/v4/letter/b/f08c70/32.png) [@ben.sharp](https://discuss.elastic.co/u/ben.sharp)
#### Post date: [March 4, 2020, 10:56am UTC](https://discuss.elastic.co/t/does-k8s-autodiscover-work-for-all-namespaces/221874/3 "2020-03-04T10:56:44Z")

</div>

I can post the full Yaml configuration file that I am using, but specifically I have the ConfigMap below which from documentation I understood to be where to put the "Metricbeat.autodiscover" options.

```auto
---

apiVersion: v1

kind: ConfigMap

metadata:

  name: metricbeat-deployment-modules

  namespace: kube-system

  labels:

    k8s-app: metricbeat

data:

  kubernetes.yml: |-

    - module: kubernetes

      metricsets:

        - state_node

        - state_deployment

        - state_replicaset

        - state_pod

        - state_container

        - event

      period: 10s

      hosts: ["kube-state-metrics.${KUBE_STATE_METRICS_NAMESPACE}:${KUBE_STATE_METRICS_PORT}"]

      enabled: true

      bearer_token_file: /var/run/secrets/kubernetes.io/serviceaccount/token

    metricbeat.autodiscover:

      providers:

        - type: kubernetes

          hints.enabled: true

```

I don't believe it is logging any errors, Metricbeat is already scraping some K8s metrics from the cluster it's running in without issue.

---

<div class="post-metadata">

### Author: ![jsoriano](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jsoriano/32/27920_2.png) [@jsoriano](https://discuss.elastic.co/u/jsoriano)
#### Post date: [March 4, 2020, 12:19pm UTC](https://discuss.elastic.co/t/does-k8s-autodiscover-work-for-all-namespaces/221874/4 "2020-03-04T12:19:51Z")

</div>

Autodiscover configuration has to be placed in the main `metricbeat.yml` configuration file, not in `kubernetes.yml`.

You can find a reference manifest for metricbeat in Kubernetes here: [https://www.elastic.co/guide/en/beats/metricbeat/7.6/running-on-kubernetes.html](https://www.elastic.co/guide/en/beats/metricbeat/7.6/running-on-kubernetes.html)

There you can see where the autodiscover configuration is placed.

---

<div class="post-metadata">

### Author: ![ben.sharp](https://avatars.discourse-cdn.com/v4/letter/b/f08c70/32.png) [@ben.sharp](https://discuss.elastic.co/u/ben.sharp)
#### Post date: [March 4, 2020, 1:27pm UTC](https://discuss.elastic.co/t/does-k8s-autodiscover-work-for-all-namespaces/221874/5 "2020-03-04T13:27:41Z")

</div>

Thanks, I will give that a go.

---

<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: [April 1, 2020, 1:27pm UTC](https://discuss.elastic.co/t/does-k8s-autodiscover-work-for-all-namespaces/221874/6 "2020-04-01T13:27:44Z")

</div>

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