This guide will walk you through the process of configuring Prometheus to scrape specific namespaces in your Kubernetes
cluster using kube-prometheus and the vars.jsonnet file.
Before proceeding with the configuration, ensure you have completed the following prerequisites:
-
Install kube-prometheus: Follow the installation guide for kube-prometheus to set up Prometheus, Grafana, and other required components in your cluster.
-
JSONnet Vars File: Ensure you have the
vars.jsonnetfile, which contains the configuration variables for kube-prometheus. Modify it according to your requirements.
-
Open the
vars.jsonnetfile:- Locate the
kubeaid-config/k8s/<clustername>/<clustername>-vars.jsonnetfile for your Kubernetes cluster. - Open the file in a text editor.
- Locate the
-
Set the Prometheus Scrape Namespaces:
-
In the
kubeaid-config/k8s/<clustername>/<clustername>-vars.jsonnetfile, locate theprometheus_scrape_namespacesfield. -
Modify the field to include the namespaces you want Prometheus to scrape.
-
For example, if you want Prometheus to scrape the
rook-cephandloggingnamespaces, update the field as follows:prometheus_scrape_namespaces: [ 'rook-ceph', 'logging', ],
-
-
Save the changes:
- Save the
kubeaid-config/k8s/<clustername>/<clustername>-vars.jsonnetfile after making the necessary modifications.
- Save the
-
Regenerate kube-prometheus YAML:
-
Run the script to regenerate the kube-prometheus YAML files using the
kubeaid-config/k8s/<clustername>/<clustername-vars>.jsonnetfile. -
Use the following command:
kubeaid/build/kube-prometheus/build.sh /path/to/kubernetes-config-company/k8s/production.company.io/production.company.io-vars.jsonnet
-
Replace the paths with the appropriate locations for your setup.
-
-
Commit and Sync:
- Commit the changes made to the
kubeaid-config/k8s/<clustername>/<clustername>-vars.jsonnetfile to your cluster configuration repository. - Sync the changes to apply the new configurations.
- Commit the changes made to the
-
Verify the Configuration:
- Ensure that the Prometheus server is scraping the desired namespaces.
- Access the Prometheus UI using port forwarding or any other method.
- Navigate to the "Status" menu in the Prometheus UI.
- Verify that the listed targets include the services and pods from the specified namespaces.
- If the targets are correctly scraped, Prometheus is successfully configured to monitor the selected namespaces.
You have now successfully configured Prometheus to scrape specific namespaces using kube-prometheus and the vars.jsonnet
file. Prometheus will now collect metrics from the specified namespaces and make them available for monitoring and analysis.
Remember to adjust the paths and namespaces based on your actual configuration.