Federation
Federation is a feature that enables you to expose metrics from your Prometheus instance to another Prometheus instance.
Use-Case: Collecting metrics from CES-instances in a centralized Prometheus
In this use-case, we may have multiple CES-instances and want to collect their metrics in a centralized Prometheus.
You can do this for as many CES-instances as you like.
Files for testing this scenario can be found in the samples folder.
Configure CES-Prometheus
First we'll have to expose our CES-Prometheus to outside the cluster.
The easiest way to do this is to create a route to it via an Ingress.
This can be done using the following valuesYamlOverwrite:
apiVersion: k8s.cloudogu.com/v1
kind: Component
metadata:
name: k8s-prometheus
labels:
app: ces
spec:
name: k8s-prometheus
namespace: k8s
version: 57.1.1-8
valuesYamlOverwrite: |
global:
ingress:
enabled: trueSince the CES-Prometheus is behind an authentication proxy, we have to create a service account by applying a Secret like the following:
apiVersion: v1
kind: Secret
metadata:
name: k8s-prometheus-auth-presets
labels:
app: ces
k8s.cloudogu.com/component.name: k8s-prometheus
stringData:
web.presets.yaml: |
basic_auth_users:
grafana-123abc: grafana-hashed-password
prometheus-exposed: bcrypt-hashed-passwordMake sure to hash the password with bcrypt, which can be done with the following command from the apache2-utils package:
htpasswd -bnBC 10 "" <your-password> | tr -d ':\n' | sed 's/$2y/$2a/'Important: If you want Grafana to be able to access Prometheus at the same time, the name of the Prometheus service account
and the corresponding (bcrypt-hashed) password must also be specified in the k8s-prometheus-auth-presets secret. The service account
is located in the grafana-config secret.
Restart the Prometheus to make the auth-proxy load the file.
Test authentication and federation with this:
wget --header="Content-Type: application/json" --header="Accept: application/json" \
--auth-no-challenge --user=prometheus-exposed --ask-password \
-O- "https://<your ces-fqdn>/prometheus/federate?match[]=%7B__name__%3D~%22.%2B%22%7D"Configure centralized Prometheus
You can then append a snippet like this to the prometheus.yaml of your centralized Prometheus to collect metrics from the CES-Prometheus:
- job_name: 'federate-ces'
scrape_interval: 15s
honor_labels: true
metrics_path: '/prometheus/federate'
params:
'match[]':
- '{__name__=~".+"}'
static_configs:
- targets: ['<your ces-fqdn>']
scheme: https
basic_auth:
username: 'prometheus-exposed'
password_file: '/path/to/your/password-file'Test federation
If you configured your local ecosystem (running at 192.168.56.2) with the auth-presets from the samples folder,
you can then start a Prometheus in docker with federation enabled using the following command:
docker run \
-p 9090:9090 \
-v $(pwd)/samples/prometheus.yaml:/etc/prometheus/prometheus.yml \
prom/prometheusYou can then query scrape_samples_scraped{job="federate-ces"} and the result to the right should not be 0.
Last updated on 7/3/2026