Set namespace of service-discovery for prometheus-operator installed by helm

Viewed 1935

I've installed the prometheus-operator by helm 3:

helm install prom stable/prometheus-operator --namespace monitor

But I also want to set the namespace for the service discovery which is "default" in the standard installation.

When I query the prometheus config, I see this:

kubernetes_sd_configs:
- role: endpoints
  namespaces:
    names:
    - default

I've checked the documentation of the prometheus-operator, but I can't find an option of how to change the default namespace.

There's a parameter serviceMonitorNamespaceSelector, but this seems to search the serviceMonitor itself in the namespace.

2 Answers

Thanks to the hint from @naga I found the solution:

Install prometheus operator with helm:

helm install prom stable/prometheus-operator --namespace monitor -f values.yaml

values.yaml configuration file:

kubelet:
  serviceMonitor:
    https:
      false
prometheus:
  additionalServiceMonitors:
    - name: my-monitor
      selector:
        matchLabels:
          app.kubernetes.io/instance : myvalue
      namespaceSelector:
        matchNames:
          - mynamespace
      endpoints:
        - port: metrics
          interval: 10s
Related