1
0
mirror of https://github.com/coreos/prometheus-operator.git synced 2026-02-05 15:46:31 +01:00

docs: clarify scrapeConfigNamespaceSelector (#8208)

* docs: clarify scrapeConfigNamespaceSelector

Signed-off-by: arpit529srivastava <arpitsrivastava529@gmail.com>

* docs: fix menu indentation

Signed-off-by: arpit529srivastava <arpitsrivastava529@gmail.com>

* docs: clarify resource and namespace selectors in Prometheus Operator CRDs

Signed-off-by: arpit529srivastava <arpitsrivastava529@gmail.com>

---------

Signed-off-by: arpit529srivastava <arpitsrivastava529@gmail.com>
This commit is contained in:
Arpit Srivastava
2026-01-14 01:48:22 +05:30
committed by GitHub
parent e7e119fbba
commit ba40a488f5
2 changed files with 59 additions and 7 deletions

View File

@@ -17,8 +17,8 @@ Kubernetes cluster or create scrape configurations that are not possible with th
## Prerequisites
* `prometheus-operator` `>v0.65.1`
* `ScrapeConfig` CRD installed in the cluster. Make sure to (re)start the operator after the CRD has been created/updated.
- `prometheus-operator` `>v0.65.1`
- `ScrapeConfig` CRD installed in the cluster. Make sure to (re)start the operator after the CRD has been created/updated.
## Configure Prometheus or PrometheusAgent to select ScrapeConfigs
@@ -35,14 +35,47 @@ spec:
With this example, all `ScrapeConfig` having the `prometheus` label set to `system-monitoring-prometheus` will be used
to generate scrape configurations.
> **Note:** Since `scrapeConfigNamespaceSelector` is not specified, this example only selects `ScrapeConfigs` from the same namespace as the Prometheus resource.
## Namespace Selection
To select `ScrapeConfigs` based on the namespace, `scrapeConfigNamespaceSelector` field can be used.
### Select ScrapeConfigs from all namespaces
Set it to `{}` to match `ScrapeConfigs` from all namespaces:
```yaml
spec:
scrapeConfigSelector:
matchLabels:
prometheus: system-monitoring-prometheus
scrapeConfigNamespaceSelector: {}
```
### Select ScrapeConfigs from namespaces with specific labels
To select `ScrapeConfigs` only from namespaces with specific labels:
```yaml
spec:
scrapeConfigSelector:
matchLabels:
prometheus: system-monitoring-prometheus
scrapeConfigNamespaceSelector:
matchLabels:
environment: production
```
## Use ScrapeConfig to scrape an external target
`ScrapeConfig` currently supports a limited set of service discoveries:
* `static_config`
* `file_sd`
* `http_sd`
* `kubernetes_sd`
* `consul_sd`
- `static_config`
- `file_sd`
- `http_sd`
- `kubernetes_sd`
- `consul_sd`
The following examples are basic and don't cover all the supported service discovery mechanisms. The CRD is constantly evolving, adding new features and support for new Service Discoveries. Check the [API documentation](https://prometheus-operator.dev/docs/api-reference/api/#monitoring.coreos.com/v1alpha1.ScrapeConfig) to see all supported fields.

View File

@@ -84,3 +84,22 @@ The `AlertmanagerConfig` CRD allows us to configure `Alertmanager` instances in
![Prometheus Rule](../img/prometheus-rule.png)
The `PrometheusRule` CRD allows the definition of alerting and recording rules to be consumed by Prometheus or Thanos Ruler instances. Alerts and recording rules are reconciled by the Operator and dynamically loaded without requiring a restart of Prometheus or Thanos Ruler.
### Resource Selectors
Instance-based resources use selector fields to discover and associate config-based resources:
* `serviceMonitorSelector` and `serviceMonitorNamespaceSelector` for `Prometheus` and `PrometheusAgent` CRDs.
* `podMonitorSelector` and `podMonitorNamespaceSelector` for `Prometheus` and `PrometheusAgent` CRDs.
* `probeSelector` and `probeNamespaceSelector` for `Prometheus` and `PrometheusAgent` CRDs.
* `scrapeConfigSelector` and `scrapeConfigNamespaceSelector` for `Prometheus` and `PrometheusAgent` CRDs.
* `ruleSelector` and `ruleNamespaceSelector` for `Prometheus` and `ThanosRuler` CRDs.
* `alertmanagerConfigSelector` and `alertmanagerConfigNamespaceSelector` for `Alertmanager` CRD.
The selector fields follow standard Kubernetes label selector semantics:
* An empty selector (`{}`) matches all objects.
* A null selector (field not specified) matches no objects for resource selectors, or only the current namespace for namespace selectors.
* Otherwise the label selector matches objects with the specified labels.
You can check the examples mentioned in the [ScrapeConfig documentation](../developer/scrapeconfig.md).