kube-prometheus-stack uses Prometheus-operator and Prometheus to provide easy-to-use, end-to-end Kubernetes cluster monitoring.
Open source community: https://github.com/prometheus/prometheus
To enable this function, on the ConfigMaps and Secrets page, expand the dropdown list of Namespace, and select monitoring. Locate the row that contains the configuration item named persistent-user-config, and click Edit YAML in the operation column. Remove the serviceMonitorDisable or podMonitorDisable configuration in the customSettings field as required or set the configuration to an empty array.
... customSettings: podMonitorDisable: [] serviceMonitorDisable: []
The node-exporter component of the kube-prometheus-stack add-on needs to read the Docker info data from the /var/run/docker.sock directory on the host for monitoring the Docker disk space.
The following permission is required for running node-exporter:
An available PVC named pvc-prometheus-server exists in namespace monitoring and will be used as the storage source.
After the add-on is installed, you may need to perform the following operations:
All Kubernetes resources created during kube-prometheus-stack add-on installation are created in the namespace named monitoring.
Component |
Description |
Supported Deployment Mode |
Resource Type |
---|---|---|---|
prometheusOperator (workload name: prometheus-operator) |
Deploys and manages the Prometheus Server based on CustomResourceDefinitions (CRDs), and monitors and processes the events related to these CRDs. It is the control center of the entire system. |
Agent/Server |
Deployment |
prometheus (workload name: prometheus-server) |
A Prometheus Server cluster deployed by the operator based on the Prometheus CRDs that can be regarded as StatefulSets. |
Agent/Server |
StatefulSet |
alertmanager (workload name: alertmanager-alertmanager) |
Alarm center of the add-on. It receives alarms sent by Prometheus and manages alarm information by deduplicating, grouping, and distributing. |
Server |
StatefulSet |
thanosSidecar |
Available only in HA mode. Runs with prometheus-server in the same pod to implement persistent storage of Prometheus metric data. |
Server |
Container |
thanosQuery |
Available only in HA mode. Entry for PromQL query when Prometheus is in HA scenarios. It can delete duplicate metrics from Store or Prometheus. |
Server |
Deployment |
adapter (workload name: custom-metrics-apiserver) |
Aggregates custom metrics to the native Kubernetes API Server. |
Server |
Deployment |
kubeStateMetrics (workload name: kube-state-metrics) |
Converts the Prometheus metric data into a format that can be identified by Kubernetes APIs. By default, the kube-state-metrics component does not collect all labels and annotations of Kubernetes resources. To collect all labels and annotations, see Collecting All Labels and Annotations of a Pod. NOTE:
If the components run in multiple pods, only one pod provides metrics. |
Agent/Server |
Deployment |
nodeExporter (workload name: node-exporter) |
Deployed on each node to collect node monitoring data. |
Agent/Server |
DaemonSet |
clusterProblemDetector (workload name: cluster-problem-detector) |
Monitors cluster exceptions. |
Server |
Deployment |
Resource metrics of containers and nodes, such as CPU and memory usage, can be obtained through the Kubernetes Metrics API. Resource metrics can be directly accessed, for example, by using the kubectl top command, or used by HPA or CustomedHPA policies for auto scaling.
The add-on can provide the Kubernetes Metrics API that is disabled by default. To enable the API, create the following APIService object:
apiVersion: apiregistration.k8s.io/v1 kind: APIService metadata: labels: app: custom-metrics-apiserver release: cceaddon-prometheus name: v1beta1.metrics.k8s.io spec: group: metrics.k8s.io groupPriorityMinimum: 100 insecureSkipTLSVerify: true service: name: custom-metrics-apiserver namespace: monitoring port: 443 version: v1beta1 versionPriority: 100
You can save the object as a file, name it metrics-apiservice.yaml, and run the following command:
kubectl create -f metrics-apiservice.yaml
Run the kubectl top pod -n monitoring command. If the following information is displayed, the Metrics API can be accessed:
# kubectl top pod -n monitoring NAME CPU(cores) MEMORY(bytes) ...... custom-metrics-apiserver-d4f556ff9-l2j2m 38m 44Mi ......
To uninstall the add-on, run the following kubectl command and delete the APIService object. Otherwise, the metrics-server add-on cannot be installed due to residual APIService resources.
kubectl delete APIService v1beta1.metrics.k8s.io
HPA policies can only be used when Cloud Native Cluster Monitoring is deployed in the server mode. You can configure custom metrics required by HPA policies in the user-adapter-config ConfigMap.
To use Prometheus to monitor custom metrics, the application needs to provide a metric monitoring API. For details, see Prometheus Monitoring Data Collection.
In this section, the nginx metric (nginx_connections_accepted) in Monitoring Custom Metrics Using Cloud Native Cluster Monitoring is used as an example.
You can add multiple collection rules by adding multiple configurations under the rules field. For details, see Metrics Discovery and Presentation Configuration.
rules: # Match the metric whose name is nginx_connections_accepted. The metric name must be confirmed. Otherwise, the HPA controller cannot get the metric. - seriesQuery: '{__name__=~"nginx_connections_accepted",container!="POD",namespace!="",pod!=""}' resources: # Specify pod and namespace resources. overrides: namespace: resource: namespace pod: resource: pod name: #Use nginx_connections_accepted" matches: "nginx_connections_accepted" #Use nginx_connections_accepted_per_second to represent the metric. The name is the custom metric name in a custom HPA policy. as: "nginx_connections_accepted_per_second" # Calculate rate(nginx_connections_accepted[2m]) to specify the number of requests received per second. metricsQuery: 'rate(<<.Series>>{<<.LabelMatchers>>,container!="POD"}[2m])'
--metric-labels-allowlist=pods=[*],nodes=[node,failure-domain.beta.kubernetes.io/zone,topology.kubernetes.io/zone]
--metric-annotations-allowlist=pods=[*],nodes=[node,failure-domain.beta.kubernetes.io/zone,topology.kubernetes.io/zone]
When editing the startup command, do not modify other original startup parameters. Otherwise, the component may be abnormal.
kubectl get servicemonitor kube-state-metrics -nmonitoring -oyaml | grep kube_pod_labels
For more kube-state-metrics startup parameters, see kube-state-metrics/cli-arguments.
Add-on Version |
Supported Cluster Version |
New Feature |
Community Version |
---|---|---|---|
3.10.1 |
v1.21 v1.23 v1.25 v1.27 v1.28 v1.29 |
The NodeExporter component is upgraded to 1.8.0. |