tencent cloud

Cloud Log Service

Collecting Kubernetes Metrics

Download
Focus Mode
Font Size
Last updated: 2026-05-27 21:13:53
This document describes how to collect metrics from self-built K8s and TKE clusters (including TKE standard clusters and TKE Serverless clusters) to CLS.

Prerequisites

Configured relevant permissions for metric reporting. For details, see Metric Reporting Access Policy Template.
A logset and metric topic have been created. For detailed instructions, see Logset and Metric Topic.

Operation Steps

Step 1: Selecting a Metric Topic

1. Log in to the CLS console.
2. In the left sidebar, select Metric Topic, choose the metric topic to collect, click the metric topic name to enter the topic details page. If you have not yet created a metric topic, click Create Metric Topic to proceed. For details, see Metric Topic.
3. On the metric topic details page, select Collection Management > Kubernetes Metrics in the left menu. Here, you can report K8s Basic Metrics and Custom Service Metrics. On the right management page, click Create to enter the corresponding K8s metric configuration process.


Step 2: Configuring K8s Metric Collection

K8s Basic Monitoring Metrics Collection
K8s Custom Service Metrics Collection
K8s Custom Service Metrics Collection (YAML Import)
1. In the Kubernetes Basic Monitoring Metrics on the right, click Create to enter the configuration process.
2. Select the cluster to collect. If metric collection is disabled for the selected cluster, hover the mouse over the red text. As instructed, enable metric collection, then just select the cluster.

3. After entering the configuration page, configure metrics collection. Here, two setting methods are provided: Quick configuration and importing Custom YAML.

Quick Configuration:
By default, some commonly used K8s basic monitoring metrics are selected. Click Edit to adjust.
Three basic metrics are provided: container usage monitoring, K8s resource status monitoring, and host monitoring.


Custom YAML: Support quickly enabling Kubernetes basic monitoring components through YAML templates to collect key metric data at the cluster, node, and container layers. Three independently controlled collection component switches are provided, each corresponding to a YAML deployment template. Based on actual business scenarios, you can perform YAML adjustments.
kube-state-metrics: Collect running status information of Kubernetes resource objects such as Deployment, Pod, and Node.
node-exporter: Collect system resource indicators at the node level.
cAdvisor: Collect container runtime metrics to monitor Pod and container resource usage.


4. Once configured, click Submit. After completion, you can start collecting.
1. In the Kubernetes Custom Service Metrics on the right, click Create to enter the configuration process.
2. Select the cluster to collect. If metric collection is disabled for the selected cluster, hover the mouse over the red text. As instructed, enable metric collection, then just select the cluster.
3. Proceed to the configuration page and configure metrics collection.

For partial content of the collection configuration, see the table below.
Parameter
Description
Configuration Name
The name of the metric collection configuration.
Workload Details
The target K8s objects for metric collection, supporting multiple selections.
Namespace: Select a namespace to collect.
Pod Label: Select target Pods by Label, support key/value configuration, multiple rules follow AND relationship.
Port: Metric collection port.
Metric Address (Path): Path for metric collection.

Data Processing
Process collected metric data with rules, where the logic is consistent with Prometheus' relabel rules. Supports configuring multiple data processing rules, executed in pipeline order by rule serial number.
Supported rule operations: Label replacement, drop Label, retain Label, lowercase, uppercase, drop metric (full/regular expression matching), retain metric (full/regular expression matching), hash modulo, Label map.
Custom Label
In addition to the original metric content, container or Kubernetes-related metadata (such as the container ID that generates the log) will also be reported to CLS, facilitating user viewing and tracing the source of metrics or searching based on container identifiers and features (such as container name, labels). You can choose whether to report this metadata as needed, upload it selectively, or submit custom metadata.

For partial content of other configuration, see the table below.
Parameter
Description
Communication protocol
The protocol used for metric collection supports HTTP or HTTPS, defaulting to HTTP.
Collection frequency
Metric collection interval, default 60s.
Collection timeout
Metric collection request timeout, default 30s.
Reserve the source tag
Whether to reserve the original metric Label, off by default.
4. Once configured, click Submit. After completion, you can start collecting.
1. In the Kubernetes Custom Service Metrics on the right, click Import via YAML to enter the configuration process.
2. Select the cluster to collect. If metric collection is disabled for the selected cluster, hover the mouse over the red text. As instructed, enable metric collection, then just select the cluster.
3. Proceed to the configuration page and configure metrics collection.
Supports four YAML types:
ServiceMonitor(Prometheus-Operator)
PodMonitor(Prometheus-Operator)
ScrapeConfig(Prometheus-Operator)
ScrapeConfig (Prometheus native)
Based on the selected type, enter configuration details in the YAML box just.

4. Once configured, click Submit. After completion, you can start collecting.

Step 3: Searching and Analyzing Metrics

You have completed the K8s metric collection configuration. Next, go to the retrieval and analysis page, select the target metric topic on the left side of the console, and you can proceed with metric retrieval and queries. For metric search syntax rules, see metric search syntax rules.


Help and Support

Was this page helpful?

Help us improve! Rate your documentation experience in 5 mins.

Feedback