Path: blob/main/docs/sources/flow/reference/components/mimir.rules.kubernetes.md
4096 views
---
---
mimir.rules.kubernetes
{{< docs/shared lookup="flow/stability/beta.md" source="agent" >}}
mimir.rules.kubernetes
discovers PrometheusRule
Kubernetes resources and loads them into a Mimir instance.
Multiple
mimir.rules.kubernetes
components can be specified by giving them different labels.Kubernetes label selectors can be used to limit the
Namespace
andPrometheusRule
resources considered during reconciliation.Compatible with the Ruler APIs of Grafana Mimir, Grafana Cloud, and Grafana Enterprise Metrics.
Compatible with the
PrometheusRule
CRD from the prometheus-operator.This component accesses the Kubernetes REST API from within a Pod.
NOTE: This component requires Role-based access control (RBAC) to be setup in Kubernetes in order for the Agent to access it via the Kubernetes REST API. For an example RBAC configuration please click here.
Usage
Arguments
mimir.rules.kubernetes
supports the following arguments:
Name | Type | Description | Default | Required |
---|---|---|---|---|
address | string | URL of the Mimir ruler. | yes | |
tenant_id | string | Mimir tenant ID. | no | |
use_legacy_routes | bool | Whether to use deprecated ruler API endpoints. | false | no |
sync_interval | duration | Amount of time between reconciliations with Mimir. | "30s" | no |
mimir_namespace_prefix | string | Prefix used to differentiate multiple agent deployments. | "agent" | no |
bearer_token | secret | Bearer token to authenticate with. | no | |
bearer_token_file | string | File containing a bearer token to authenticate with. | no | |
proxy_url | string | HTTP proxy to proxy requests through. | no | |
follow_redirects | bool | Whether redirects returned by the server should be followed. | true | no |
enable_http2 | bool | Whether HTTP2 is supported for requests. | true | no |
At most one of the following can be provided:
If no tenant_id
is provided, the component assumes that the Mimir instance at address
is running in single-tenant mode and no X-Scope-OrgID
header is sent.
The sync_interval
argument determines how often Mimir's ruler API is accessed to reload the current state of rules. Interaction with the Kubernetes API works differently. Updates are processed as events from the Kubernetes API server according to the informer pattern.
The mimir_namespace_prefix
argument can be used to separate the rules managed by multiple agent deployments across your infrastructure. It should be set to a unique value for each deployment.
Blocks
The following blocks are supported inside the definition of mimir.rules.kubernetes
:
Hierarchy | Block | Description | Required |
---|---|---|---|
rule_namespace_selector | label_selector | Label selector for Namespace resources. | no |
rule_namespace_selector > match_expression | match_expression | Label match expression for Namespace resources. | no |
rule_selector | label_selector | Label selector for PrometheusRule resources. | no |
rule_selector > match_expression | match_expression | Label match expression for PrometheusRule resources. | no |
basic_auth | basic_auth | Configure basic_auth for authenticating to the endpoint. | no |
authorization | authorization | Configure generic authorization to the endpoint. | no |
oauth2 | oauth2 | Configure OAuth2 for authenticating to the endpoint. | no |
oauth2 > tls_config | tls_config | Configure TLS settings for connecting to the endpoint. | no |
tls_config | tls_config | Configure TLS settings for connecting to the endpoint. | no |
The >
symbol indicates deeper levels of nesting. For example, oauth2 > tls_config
refers to a tls_config
block defined inside an oauth2
block.
label_selector block
The label_selector
block describes a Kubernetes label selector for rule or namespace discovery.
The following arguments are supported:
Name | Type | Description | Default | Required |
---|---|---|---|---|
match_labels | map(string) | Label keys and values used to discover resources. | {} | yes |
When the match_labels
argument is empty, all resources will be matched.
match_expression block
The match_expression
block describes a Kubernetes label match expression for rule or namespace discovery.
The following arguments are supported:
Name | Type | Description | Default | Required |
---|---|---|---|---|
key | string | The label name to match against. | yes | |
operator | string | The operator to use when matching. | yes | |
values | list(string) | The values used when matching. | no |
The operator
argument should be one of the following strings:
"in"
"notin"
"exists"
basic_auth block
{{< docs/shared lookup="flow/reference/components/basic-auth-block.md" source="agent" >}}
authorization block
{{< docs/shared lookup="flow/reference/components/authorization-block.md" source="agent" >}}
oauth2 block
{{< docs/shared lookup="flow/reference/components/oauth2-block.md" source="agent" >}}
tls_config block
{{< docs/shared lookup="flow/reference/components/tls-config-block.md" source="agent" >}}
Exported fields
mimir.rules.kubernetes
does not export any fields.
Component health
mimir.rules.kubernetes
is reported as unhealthy if given an invalid configuration or an error occurs during reconciliation.
Debug information
mimir.rules.kubernetes
exposes resource-level debug information.
The following are exposed per discovered PrometheusRule
resource:
The Kubernetes namespace.
The resource name.
The resource uid.
The number of rule groups.
The following are exposed per discovered Mimir rule namespace resource:
The namespace name.
The number of rule groups.
Only resources managed by the component are exposed - regardless of how many actually exist.
Debug metrics
Metric Name | Type | Description |
---|---|---|
mimir_rules_config_updates_total | counter | Number of times the configuration has been updated. |
mimir_rules_events_total | counter | Number of events processed, partitioned by event type. |
mimir_rules_events_failed_total | counter | Number of events that failed to be processed, partitioned by event type. |
mimir_rules_events_retried_total | counter | Number of events that were retried, partitioned by event type. |
mimir_rules_client_request_duration_seconds | histogram | Duration of requests to the Mimir API. |
Example
This example creates a mimir.rules.kubernetes
component that loads discovered rules to a local Mimir instance under the team-a
tenant. Only namespaces and rules with the agent
label set to yes
are included.
This example creates a mimir.rules.kubernetes
component that loads discovered rules to Grafana Cloud.
The following example is an RBAC configuration for Kubernetes. It authorizes the Agent to query the Kubernetes REST API: