Kubelet/cAdvisor

The Kubelet exposes metrics about itself as well as cAdvisor metrics about containers running on its node. Instead of using a custom PodMonitoring config, you can configure managed collection to automatically scrape Kubelet and cAdvisor metrics by editing the OperatorConfig.

You can install manifests by copying them to a local file and then running kubectl apply -f FILE_NAME. You can also install manifests by using Terraform.

  1. Open the OperatorConfig resource for editing:

    kubectl -n gmp-public edit operatorconfig config
    
  2. Add the following collection section, shown in bold type, to the resource:

    apiVersion: monitoring.googleapis.com/v1
    kind: OperatorConfig
    metadata:
      namespace: gmp-public
      name: config
    collection:
      kubeletScraping:
        interval: 30s
    
  3. Save the file and close the editor.

After a short time, the Kubelet metric endpoints will be scraped and the metrics become available for querying in Managed Service for Prometheus.

Kubelet scraping comes with some default filters, and you can add additional filters to the collection section of the OperatorConfig resource as shown below. The filter.matchOneOf configuration section has the same semantics as the match[] parameters for Prometheus federation.

The following example filters out metrics that start with container_foo or container_bar:

collection:
  filter:
    matchOneOf:
    - '{__name__!~"container_foo.*|container_bar.*"}'

You can also use this OperatorConfig collection filter for debugging purposes. For example, you might want to temporarily disable collection of a particular metric in your cluster without modifying any PodMonitoring resource.

Tips for advanced cAdvisor setups

If you self-deploy cAdvisor or provide advanced configuration to your Kubelet with cAdvisor, be aware that additional labels can be attached by using advanced cAdvisor settings.

Particularly avoid attaching Kubernetes container labels or environment variables to your metrics, and if you do, strictly control these labels by using an allowlist pattern (for example, using PodMonitoring's metricRelabeling section).

Controlling the number of labels added to your metrics can help you avoid exceeding the limit on the number of labels.