Skip to main content
In this tutorial, you’ll learn how to deploy the Kube Prometheus Stack on Kubernetes using Flux 2 GitOps components. By the end, you’ll have Prometheus and Grafana running on your cluster, exposed via NodePort services.

Why Use Flux 2 for Monitoring?

Using Flux 2 to manage your monitoring stack as GitOps ensures:
  • Declarative configuration
  • Automated drift detection and remediation
  • Version control of all resource definitions

1. Prepare the Flux Monitoring Manifests

Flux maintains example manifests for the Kube Prometheus Stack in its repository under manifests/monitoring/kube-prometheus-stack:
The image shows a GitHub repository page for "fluxcd/flux2" with a focus on the "kube-prometheus-stack" directory, displaying several YAML files and their last update details.
Here are the two key resources you will apply:

a. HelmRepository

This resource fetches the Helm charts from the Prometheus Community Helm Repository:

b. HelmRelease

The HelmRelease installs version 0.45.x of the kube-prometheus-stack chart into the monitoring namespace. It also configures custom retention and resource requests:
Defining crds: Create ensures that all CustomResourceDefinitions required by the chart are installed before the HelmRelease.

2. Deploy the Flux Resources

In your cluster Git repository (for example, flux-clusters/dev-cluster), create the Flux sources and kustomization:
Make sure the monitoring namespace does not already exist or is managed by another tool, as Flux will create it.

3. Verify Deployment

After Flux syncs, confirm that the monitoring namespace and its resources are created:

4. Expose Prometheus and Grafana

By default, both Prometheus and Grafana services use ClusterIP. To access them externally, switch to NodePort:
Example output:

5. Access the Prometheus UI

Open the Prometheus interface in your browser at http://<node-ip>:30753. The dashboard displays service monitor health:
The image shows a Prometheus monitoring dashboard displaying the status of various service monitors, with some endpoints marked as "UP" and one as "DOWN," indicating their health status.

6. Access the Grafana Dashboard

Visit http://<node-ip>:31921 and log in with credentials stored in the kube-prometheus-stack-grafana secret:
Decode the base64 values:
Initially, no Flux-specific dashboards are available:
The image shows the Grafana dashboard interface, featuring options for creating new dashboards and adding data sources, along with a blog update section.
However, you can browse the built-in Kubernetes monitoring dashboards:
The image shows a Grafana dashboard interface with a list of various monitoring dashboards related to Kubernetes and other services. The interface includes options for browsing, filtering, and sorting the dashboards.

7. Explore Prometheus Targets

Check the Prometheus /targets page to see which endpoints are scraped:
The image shows a Prometheus monitoring dashboard displaying a list of service targets, with some services marked as unhealthy in red and others as healthy in blue.

Next Steps

  • Configure ServiceMonitor resources to scrape Flux controllers.
  • Deploy custom Grafana dashboards for Flux metrics.
  • Integrate alerts into your incident management workflow.

References

Watch Video