Learn to update Kubernetes deployment for Prometheus scrape targets using Helm values file and service discovery methods.
In this lesson, you’ll learn how to update your Kubernetes deployment to ensure Prometheus is aware of new scrape targets. There are two methods for this configuration: one approach, which involves directly modifying additional scrape configurations in a Helm values file, and a more optimal method using service discovery that aligns with Prometheus Operator best practices. In the following sections, we’ll start by exploring the less preferred approach and then cover how to use service discovery for a dynamic setup.
When you first worked with Helm, you learned about the values file that enables you to customize a Helm chart. To get a comprehensive view of all configuration options available in the “prometheus-community/kube-prometheus-stack” chart, extract the default values to a file. This file provides insight into every available configuration setting, including the “additionalScrapeConfigs” section.For example, consider the simple service definition below:
To view the default values for this Helm chart, run the following command:
Copy
Ask AI
helm show values prometheus-community/kube-prometheus-stack > values.yaml
This command generates a comprehensive list of configuration options. When you search for “additional scrape” within the file, you will find a section that looks similar to this:
This section enables you to add custom scrape configurations, similar to how jobs are configured directly on your Prometheus server.
Any modifications made in the additionalScrapeConfigs section are not validated by Prometheus, and incorrect configurations might cause upgrade failures.
This command applies your new scrape configurations, ensuring that Prometheus can now monitor the additional targets. Although this configuration method works, it might cause issues during upgrades due to its rigid nature.
In the next section, we will demonstrate how to use service discovery to declaratively and dynamically add new scrape configurations to Prometheus, offering a more flexible and robust solution.
With these steps, your Prometheus deployment will be updated to include the new targets added via your additional scrape configurations, allowing you to monitor your Kubernetes environment more effectively.For further reading, check out these resources: Kubernetes Basics, Prometheus Documentation.