Learn Kubernetes in a Month of Lunches by Elton Stoneman

Learn Kubernetes in a Month of Lunches by Elton Stoneman

Author:Elton Stoneman [Stoneman, Elton]
Language: eng
Format: epub, mobi
Publisher: Manning Publications Co.
Published: 0101-01-01T00:00:00+00:00


Figure 14.2 No targets yet, but Prometheus will keep checking the Kubernetes API for new Pods.

Configuring Prometheus to find targets in Kubernetes is fairly straightforward, although the terminology is confusing at first. Prometheus uses jobs to define a related set of targets to scrape, which could be multiple components of an application. The scrape configuration can be as simple as a static list of domain names, which Prometheus polls to grab the metrics, or it can use dynamic service discovery. Listing 14.1 shows the beginning of the test-pods job configuration, which uses the Kubernetes API for service discovery.

Listing 14.1 prometheus-config.yaml, scrape configuration with Kubernetes

scrape_configs: # This is the YAML inside the ConfigMap. - job_name: 'test-pods' # Used for test apps kubernetes_sd_configs: # Finds targets from the Kubernetes API - role: pod # Searches for Pods relabel_configs: # Applies these filtering rules - source_labels: - __meta_kubernetes_namespace action: keep # Includes Pods only where the namespace regex: kiamol-ch14-test # is the test namespace for this chapter

It’s the relabel_configs section that needs explanation. Prometheus stores metrics with labels, which are key-value pairs that identify the source system and other relevant information. You’ll use labels in queries to select or aggregate metrics, and you can also use them to filter or modify metrics before they are stored in Prometheus. This is relabeling, and conceptually, it’s similar to the data pipeline in Fluent Bit—it’s your chance to discard data you don’t want and reshape the data you do want.

Regular expressions rear their unnecessarily complicated heads in Prometheus, too, but it’s rare that you need to make changes. The pipeline you set up in the relabeling phase should be generic enough to work for all your apps. The full pipeline in the configuration file applies the following rules:

Include Pods only from the namespace kiamol-ch14-test.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.