2
votes

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

2 Answers

2
votes

A ServiceMonitor object should be created in the required namespace with proper labels for Prometheus Operator to process it.

Refer to https://coreos.com/operators/prometheus/docs/latest/api.html#servicemonitorspec.

1
votes

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