About the Prometheus Operator

In Overview of the TimesTen Kubernetes Operator and the TimesTen Exporter, we discussed how the TimesTen Operator and the TimesTen exporter work together to collect and export TimesTen metrics. Now let's look at how we can expose these metrics to Prometheus.

Note:

You can expose TimesTen metrics to any scraping target. Our documentation focuses on Prometheus.

There are several ways to configure Prometheus in Kubernetes. One of the most popular is the Prometheus Operator. The Prometheus Operator simplifies the deployment, monitoring, and management of Prometheus in Kubernetes.

Similar to the TimesTen Kubernetes Operator, the Prometheus Operator add several custom resource definitions (CRDs) to Kubernetes. Just as you deploy TimesTen by creating an object of type TimesTenClassic or type TimesTenScaleout, deploying Prometheus in Kubernetes involves creating an object of type Prometheus. The Prometheus Operator automatically detects the creation of such an object and responds by starting a server using the configuration included in the object.

Note:

It is beyond the scope of this book to detail how to create an object of type Prometheus. Refer to the Prometheus Operator documentation.

The Prometheus Operator also simplifies the configuration of Prometheus servers that it deploys. The Prometheus Operator can automatically edit the Prometheus server's configuration files to include data sources that should be scraped from the /metrics endpoint. This is done through the creation of Kubernetes objects of type ServiceMonitor and of type PodMonitor. (The ServiceMonitor object type is discussed in About Creating ServiceMonitor Objects.)

For details on these object types, see Prometheus Operator API Reference.

Let's look at a basic example of a PodMonitor object:
apiVersion: monitoring.coreos.com/v1
kind: PodMonitor
metadata:
  name: sample
spec:
  selector:
    matchLabels:
      app: sample
  podMetricsEndpoints:
  - port: metrics

If you create such a PodMonitor object, the Prometheus Operator automatically responds by editing the Prometheus server's configuration files to cause the Prometheus server to scrape metrics from any Pod created with a label of app: sample. All Pods with the specified label automatically appear as scrape targets in Kubernetes. As Pods matching the selector are created or deleted, the Prometheus configuration is automatically kept in synchronization.

Using a Prometheus Operator offers a simplified approach to not only deploying, managing, and monitoring Prometheus, but also configuring Prometheus servers.