Skip to content

luweglarz/blackbox-module-operator

Repository files navigation

blackbox-module-operator

A Kubernetes operator that manages blackbox_exporter probe modules as custom resources. Instead of manually editing a monolithic ConfigMap, you define individual BlackboxModule CRs and the operator aggregates them into the blackbox_exporter configuration.

Description

This operator watches BlackboxModule custom resources and reconciles them into a single ConfigMap consumed by blackbox_exporter. This enables:

  • GitOps-friendly probe module management — each module is its own CR
  • Team-scoped ownership — RBAC controls who can create/modify which modules
  • Automatic aggregation — all modules are merged into the blackbox_exporter config.yml

Example

apiVersion: module.monitoring.ruup.amadeus.net/v1alpha1
kind: BlackboxModule
metadata:
  name: http-2xx
spec:
  prober: http
  timeout: "5s"
  http:
    validStatusCodes: [200, 201, 202]
    method: GET
    followRedirects: true
    failIfNotSsl: true
    tlsConfig:
      insecureSkipVerify: false

How It Works

  1. You create BlackboxModule custom resources (one per probe module) in any namespace.
  2. The operator watches all BlackboxModule CRs and aggregates them into a single ConfigMap (default: blackbox-exporter-config in the monitoring namespace).
  3. The ConfigMap is created automatically if it doesn't exist.
  4. Each module is keyed as <namespace>/<name> in the config.yml data.
  5. After updating the ConfigMap, the operator triggers a reload on blackbox_exporter via its /-/reload HTTP endpoint (if --blackbox-reload-url is configured).

Note: the /-/reload endpoint is only served when blackbox_exporter is started with --web.enable-lifecycle (it can otherwise reload on SIGHUP). The ConfigMap is consumed as a mounted volume, so there is a propagation delay between the operator updating the ConfigMap and the new file being visible to the blackbox_exporter pod; --reload-delay accounts for this before the reload is triggered.

Secrets

Because every module spec is serialized into the shared ConfigMap, credentials must not be set inline — they would be persisted in plaintext and readable by anyone with get access to the ConfigMap. The validating webhook rejects inline http.basicAuth.password, http.authorization.credentials, and http.oauth2.clientSecret. Use the file- or secret-ref-based variants instead (passwordFile, credentialsFile, clientSecretFile/clientSecretRef), mounting the secret into the blackbox_exporter pod.

Getting Started

Prerequisites

  • go version v1.22.0+
  • docker version 17.03+.
  • kubectl version v1.11.3+.
  • Access to a Kubernetes v1.11.3+ cluster.

Configuration

The operator accepts the following flags:

Flag Default Description
--configmap-namespace monitoring Namespace of the blackbox_exporter ConfigMap
--configmap-name blackbox-exporter-config Name of the ConfigMap to manage
--blackbox-reload-url (empty) URL to trigger blackbox_exporter reload (e.g. http://blackbox-exporter.monitoring.svc:9115/-/reload)
--reload-delay 10s Delay before triggering reload, to allow ConfigMap volume propagation
--reload-timeout 30s Timeout for a single blackbox_exporter reload request
--metrics-bind-address 0 Address for the metrics endpoint
--health-probe-bind-address :8081 Address for health probes
--leader-elect false Enable leader election for HA

To Deploy on the cluster

Build and push your image to the location specified by IMG:

make docker-build docker-push IMG=<some-registry>/blackbox-module-operator:tag

NOTE: This image ought to be published in the personal registry you specified. And it is required to have access to pull the image from the working environment. Make sure you have the proper permission to the registry if the above commands don’t work.

Install the CRDs into the cluster:

make install

Deploy the Manager to the cluster with the image specified by IMG:

make deploy IMG=<some-registry>/blackbox-module-operator:tag

NOTE: If you encounter RBAC errors, you may need to grant yourself cluster-admin privileges or be logged in as admin.

Create instances of your solution You can apply the samples (examples) from the config/sample:

kubectl apply -k config/samples/

NOTE: Ensure that the samples has default values to test it out.

To Uninstall

Delete the instances (CRs) from the cluster:

kubectl delete -k config/samples/

Delete the APIs(CRDs) from the cluster:

make uninstall

UnDeploy the controller from the cluster:

make undeploy

Project Distribution

Following are the steps to build the installer and distribute this project to users.

  1. Build the installer for the image built and published in the registry:
make build-installer IMG=<some-registry>/blackbox-module-operator:tag

NOTE: The makefile target mentioned above generates an 'install.yaml' file in the dist directory. This file contains all the resources built with Kustomize, which are necessary to install this project without its dependencies.

  1. Using the installer

Users can just run kubectl apply -f to install the project, i.e.:

kubectl apply -f https://raw.githubusercontent.com/<org>/blackbox-module-operator/<tag or branch>/dist/install.yaml

Contributing

Contributions are welcome. Please open an issue or submit a pull request.

NOTE: Run make help for more information on all potential make targets

More information can be found via the Kubebuilder Documentation

License

Copyright 2025.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors