{"id":1047,"date":"2021-04-23T15:37:05","date_gmt":"2021-04-23T07:37:05","guid":{"rendered":"https:\/\/www.linuxdevops.cn\/?p=1047"},"modified":"2021-04-23T15:52:54","modified_gmt":"2021-04-23T07:52:54","slug":"prometheus-operator-component-introduction-and","status":"publish","type":"post","link":"https:\/\/www.linuxdevops.cn\/2021\/04\/prometheus-operator-component-introduction-and\/","title":{"rendered":"Prometheus Operator\u7ec4\u4ef6\u7b80\u4ecb\u914d\u7f6e\u89e3\u6790"},"content":{"rendered":"
Prometheus Operator \u662f CoreOS \u5f00\u53d1\u7684\u57fa\u4e8e Prometheus \u7684 Kubernetes \u76d1\u63a7\u65b9\u6848\uff0c\u4e5f\u662f\u76ee\u524d\u529f\u80fd\u6700\u5168\u9762\u7684\u5f00\u6e90\u65b9\u6848\u3002<\/p>\n
\n\u901a\u8fc7helm \u5b89\u88c5\u90e8\u7f72 \u5b98\u65b9\u6587\u6863<\/strong><\/a> \u6d4b\u8bd5\u5b89\u88c5\u8fd8\u662f\u5f88\u7b80\u5355\u7684\uff0c\u5b98\u65b9\u6587\u6863\u66f4\u52a0\u8be6\u7ec6\uff0c\u672c\u6587\u4e3b\u8981\u505aPrometheus Operator \u5404\u7ec4\u4ef6\u4ecb\u7ecd\u53ca\u91cd\u8981\u914d\u7f6e\u89e3\u6790\u3002<\/p>\n<\/blockquote>\n
Prometheus Operator\u67b6\u6784\u56fe<\/h2>\n
<\/p>\n
\u4ee5\u4e0a\u67b6\u6784\u4e2d\u7684\u5404\u7ec4\u6210\u90e8\u5206\u90fd\u662f\u4ee5\u4e0d\u540c\u65b9\u5f0f\u8fd0\u884c\u5728kubernetes\u96c6\u7fa4\u4e2d\u7684kubernetes\u8d44\u6e90\uff0c\u5b83\u4eec\u5404\u81ea\u7684\u529f\u80fd\u5982\u4e0b\uff1a<\/p>\n
Operator<\/strong><\/h2>\n
Operator\u5728Kubernetes\u4e2d\u4ee5Deployment\u8fd0\u884c\uff0c\u5176\u804c\u8d23\u662f\u6839\u636e\u81ea\u5b9a\u4e49\u8d44\u6e90\uff08Custom Resource Definition \/ CRDs\uff09\u6765\u90e8\u7f72\u548c\u7ba1\u7406 Prometheus Server\uff0c\u540c\u65f6\u76d1\u63a7\u8fd9\u4e9b\u81ea\u5b9a\u4e49\u8d44\u6e90\u4e8b\u4ef6\u7684\u53d8\u5316\u6765\u505a\u76f8\u5e94\u7684\u5904\u7406\uff0c\u662f\u6574\u4e2a\u7cfb\u7edf\u7684\u63a7\u5236\u4e2d\u5fc3\u3002<\/p>\n
Prometheus<\/h2>\n
Prometheus \u81ea\u5b9a\u4e49\u8d44\u6e90\uff08CRD\uff09\u58f0\u660e\u4e86\u5728 Kubernetes \u96c6\u7fa4\u4e2d\u8fd0\u884c\u7684 Prometheus \u7684\u671f\u671b\u8bbe\u7f6e\u3002\u5305\u542b\u4e86\u526f\u672c\u6570\u91cf\uff0c\u6301\u4e45\u5316\u5b58\u50a8\uff0c\u4ee5\u53ca Prometheus \u5b9e\u4f8b\u53d1\u9001\u8b66\u544a\u5230\u7684 Alertmanagers\u7b49\u914d\u7f6e\u9009\u9879\u3002<\/p>\n
Prometeus \u81ea\u5b9a\u4e49\u8d44\u6e90\u5728Kubernetes\u4e2d\u4ee5StatefulSet\u8fd0\u884c\u7531Operator\u521b\u5efa\u548cOperator\u540c\u4e00namespace\u3002<\/p>\n
Prometheus Pod \u90fd\u4f1a\u6302\u8f7d\u4e00\u4e2a\u540d\u4e3a
\u7684 Secret\uff0c\u8be5Secret\u662f Prometheus \u7684\u76f8\u5173\u914d\u7f6e\u3002Operator \u6839\u636e\u5305\u542b\u7684 ServiceMonitor \u751f\u6210\u914d\u7f6e\uff0c\u5e76\u4e14\u66f4\u65b0\u76f8\u5173 Secret\u3002\u65e0\u8bba\u662f\u5bf9 ServiceMonitors \u6216\u8005 Prometheus \u7684\u4fee\u6539\uff0cOperator \u90fd\u4f1a\u5b9e\u65f6\u66f4\u65b0\u5728Secret\u91cc\u3002<\/p>\n \u4e00\u4e2a\u6837\u4f8b\u914d\u7f6e\u5982\u4e0b\uff1a<\/p>\n
Prometheus \u914d\u7f6e<\/strong><\/a><\/p>\n
apiVersion: monitoring.coreos.com\/v1\n kind: Prometheus\n metadata: # \u7565\u3002\u3002\u3002\u3002\n spec:\n alerting:\n alertmanagers: #Prometheus \u5bf9\u63a5\u7684 Alertmanager \u96c6\u7fa4\u7684\u540d\u5b57, \u5728 monitor \u8fd9\u4e2a namespace \u4e2d\n - apiVersion: v2\n name: prometheus-kube-prometheus-alertmanager\n namespace: monitor\n pathPrefix: \/\n port: web\n arbitraryFSAccessThroughSMs: {}\n externalUrl: http:\/\/prometheus-dev.rencaiyoujia.cn\/\n image: quay.io\/prometheus\/prometheus:v2.26.0\n logFormat: logfmt\n logLevel: info\n podMonitorNamespaceSelector: {} # podMonitor\u9009\u62e9\u540d\u79f0\u7a7a\u95f4\uff0c\u7a7a\u4e3a\u6240\u6709\n podMonitorSelector: #podMonitor \u9009\u62e9\u6807\u7b7e\uff0c \u5fc5\u987b\u5e26\u6709\u8fd9\u4e2a\u6807\u7b7e\u624d\u80fd\u88abPrometheus \u5339\u914d\u5230\u3002\n matchLabels:\n release: prometheus\n portName: web\n replicas: 1\n resources: {}\n retention: 10d\n routePrefix: \/\n ruleNamespaceSelector: {} # PrometheusRule \u9009\u62e9\u7684\u540d\u79f0\u7a7a\u95f4\uff0c\u7a7a\u4e3a\u6240\u6709\n ruleSelector: # PrometheusRule \u5fc5\u987b\u5e26\u6709\u8fd9\u4e24\u4e2a\u6807\u7b7e\u624d\u80fd\u88abPrometheus \u5339\u914d\u5230\u3002\n matchLabels:\n app: kube-prometheus-stack\n release: prometheus\n rules:\n alert: {}\n securityContext:\n fsGroup: 2000\n runAsGroup: 2000\n runAsNonRoot: true\n runAsUser: 1000\n serviceAccountName: prometheus-kube-prometheus-prometheus\n serviceMonitorNamespaceSelector: {} # serviceMonitor \u9009\u62e9\u7684\u540d\u79f0\u7a7a\u95f4\uff0c\u7a7a\u4e3a\u6240\u6709\n serviceMonitorSelector: # serviceMonitor \u5fc5\u987b\u5e26\u6709\u8fd9\u4e2a\u6807\u7b7e\u624d\u80fd\u88ab Prometheus \u5339\u914d\u5230\u3002\n matchLabels:\n release: prometheus\n version: v2.26.0\n<\/code><\/pre>\n
<\/p>\n
Prometheus Server<\/strong><\/h2>\n
Prometheus Server\u4f1a\u4f5c\u4e3aKubernetes pod \u5e94\u7528\u90e8\u7f72\u5230\u96c6\u7fa4\u4e2d\uff0c Prometheus Server\u4e3b\u8981\u8d1f\u8d23\u6570\u636e\u7684\u6536\u96c6\uff0c\u5b58\u50a8\u5e76\u4e14\u5bf9\u5916\u63d0\u4f9b\u6570\u636e\u67e5\u8be2\u652f\u6301\u3002\u800c\u5b9e\u9645\u7684\u76d1\u63a7\u6837\u672c\u6570\u636e\u7684\u6536\u96c6\u5219\u662f\u7531Exporter\u5b8c\u6210\u3002Exporter\u53ef\u4ee5\u662f\u4e00\u4e2a\u72ec\u7acb\u8fd0\u884c\u7684\u8fdb\u7a0b\uff0c\u5bf9\u5916\u66b4\u9732\u4e00\u4e2a\u7528\u4e8e\u83b7\u53d6\u76d1\u63a7\u6570\u636e\u7684HTTP\u670d\u52a1\u3002 Prometheus Server\u53ea\u9700\u8981\u5b9a\u65f6\u4ece\u8fd9\u4e9bExporter\u66b4\u9732\u7684HTTP\u670d\u52a1\u83b7\u53d6\u76d1\u63a7\u6570\u636e\u5373\u53ef\u3002<\/p>\n
<\/p>\n
ServiceMonitor<\/strong><\/h2>\n
ServiceMonitor \u4e5f\u662f\u4e00\u4e2a\u81ea\u5b9a\u4e49\u8d44\u6e90\uff0c\u5b83\u63cf\u8ff0\u4e86\u4e00\u7ec4\u88ab Prometheus \u76d1\u63a7\u7684 targets \u5217\u8868\u3002\u8be5\u8d44\u6e90\u901a\u8fc7 Labels \u6765\u9009\u53d6\u5bf9\u5e94\u7684 Service Endpoint\uff0c\u8ba9 Prometheus Server \u901a\u8fc7\u9009\u53d6\u7684 Service \u6765\u83b7\u53d6 Metrics \u4fe1\u606f\u3002<\/p>\n
Operator \u80fd\u591f\u52a8\u6001\u66f4\u65b0 Prometheus \u7684 Target \u5217\u8868\uff0cServiceMonitor \u5c31\u662f Target \u7684\u62bd\u8c61\u3002\u6bd4\u5982\u60f3\u76d1\u63a7 Kubernetes Scheduler\uff0c\u7528\u6237\u53ef\u4ee5\u521b\u5efa\u4e00\u4e2a\u4e0e Scheduler Service \u76f8\u6620\u5c04\u7684 ServiceMonitor \u5bf9\u8c61\u3002Operator \u5219\u4f1a\u53d1\u73b0\u8fd9\u4e2a\u65b0\u7684 ServiceMonitor\uff0c\u5e76\u5c06 Scheduler \u7684 Target \u6dfb\u52a0\u5230 Prometheus \u7684\u76d1\u63a7\u5217\u8868\u4e2d\u3002<\/p>\n
\u8981\u60f3\u4f7f\u7528 Prometheus Operator \u76d1\u63a7 Kubernetes \u96c6\u7fa4\u4e2d\u7684\u5e94\u7528\uff0cEndpoints \u5bf9\u8c61\u5fc5\u987b\u5b58\u5728\u3002Endpoints \u5bf9\u8c61\u672c\u8d28\u662f\u4e00\u4e2a IP \u5730\u5740\u5217\u8868\u3002\u901a\u5e38\uff0cEndpoints \u5bf9\u8c61\u7531 Service \u6784\u5efa\u3002Service \u5bf9\u8c61\u901a\u8fc7\u5bf9\u8c61\u9009\u62e9\u5668\u53d1\u73b0 Pod \u5e76\u5c06\u5b83\u4eec\u6dfb\u52a0\u5230 Endpoints \u5bf9\u8c61\u4e2d\u3002<\/p>\n
\u4e00\u4e2a Service \u53ef\u4ee5\u516c\u5f00\u4e00\u4e2a\u6216\u591a\u4e2a\u670d\u52a1\u7aef\u53e3\uff0c\u901a\u5e38\u60c5\u51b5\u4e0b\uff0c\u8fd9\u4e9b\u7aef\u53e3\u7531\u6307\u5411\u4e00\u4e2a Pod \u7684\u591a\u4e2a Endpoints \u652f\u6301\u3002\u8fd9\u4e5f\u53cd\u6620\u5728\u5404\u81ea\u7684 Endpoints \u5bf9\u8c61\u4e2d\u3002<\/p>\n
Prometheus Operator \u5f15\u5165 ServiceMonitor \u5bf9\u8c61\uff0c\u5b83\u53d1\u73b0 Endpoints \u5bf9\u8c61\u5e76\u914d\u7f6e Prometheus \u53bb\u76d1\u63a7\u8fd9\u4e9b Pods\u3002<\/p>\n
ServiceMonitorSpec \u7684 endpoints \u90e8\u5206\u7528\u4e8e\u914d\u7f6e\u9700\u8981\u6536\u96c6 metrics \u7684 Endpoints \u7684\u7aef\u53e3\u548c\u5176\u4ed6\u53c2\u6570\u3002\u5728\u4e00\u4e9b\u7528\u4f8b\u4e2d\u4f1a\u76f4\u63a5\u76d1\u63a7\u4e0d\u5728\u670d\u52a1 endpoints \u4e2d\u7684 pods \u7684\u7aef\u53e3\u3002\u56e0\u6b64\uff0c\u5728 endpoints \u90e8\u5206\u6307\u5b9a endpoint \u65f6\uff0c\u8bf7\u4e25\u683c\u4f7f\u7528\uff0c\u4e0d\u8981\u6df7\u6dc6\u3002<\/p>\n
\n\u6ce8\u610f\uff1aendpoints\uff08\u5c0f\u5199\uff09\u662f ServiceMonitor CRD \u4e2d\u7684\u4e00\u4e2a\u5b57\u6bb5\uff0c\u800c Endpoints\uff08\u5927\u5199\uff09\u662f Kubernetes \u8d44\u6e90\u7c7b\u578b\u3002<\/p>\n<\/blockquote>\n
ServiceMonitor \u548c\u53d1\u73b0\u7684\u76ee\u6807\u53ef\u80fd\u6765\u81ea\u4efb\u4f55 namespace\u3002\u8fd9\u5bf9\u4e8e\u8de8 namespace \u7684\u76d1\u63a7\u5341\u5206\u91cd\u8981\uff0c\u6bd4\u5982 meta-monitoring\u3002\u4f7f\u7528 PrometheusSpec \u4e0b ServiceMonitorNamespaceSelector, \u901a\u8fc7\u5404\u81ea Prometheus server \u9650\u5236 ServiceMonitors \u4f5c\u7528 namespece\u3002\u4f7f\u7528 ServiceMonitorSpec \u4e0b\u7684 namespaceSelector \u53ef\u4ee5\u73b0\u5728\u5141\u8bb8\u53d1\u73b0 Endpoints \u5bf9\u8c61\u7684\u547d\u540d\u7a7a\u95f4\u3002\u8981\u53d1\u73b0\u6240\u6709\u547d\u540d\u7a7a\u95f4\u4e0b\u7684\u76ee\u6807\uff0cnamespaceSelector \u5fc5\u987b\u4e3a\u7a7a\u3002<\/p>\n
\u4e00\u4e2a\u6837\u4f8b\u914d\u7f6e\u5982\u4e0b\uff1a<\/p>\n
ServiceMonitor \u914d\u7f6e<\/a><\/p>\n
apiVersion: monitoring.coreos.com\/v1\n kind: ServiceMonitor #\u81ea\u5b9a\u4e49\u8d44\u6e90\n metadata:\n annotations:\n meta.helm.sh\/release-name: prometheus\n meta.helm.sh\/release-namespace: monitor\n creationTimestamp: "2021-04-19T08:12:35Z"\n generation: 1\n labels:\n app: kube-prometheus-stack-alertmanager\n app.kubernetes.io\/managed-by: Helm\n chart: kube-prometheus-stack-14.9.0\n heritage: Helm\n release: prometheus #\u5fc5\u987b\u5e26\u6709\u6b64\u6807\u7b7e\u624d\u80fd\u88abprometheus \u9009\u62e9\u5230\uff0c\u5728prometheus \u81ea\u5b9a\u4e49\u8d44\u6e90\u4e2d\u914d\u7f6e\u3002\n name: prometheus-kube-prometheus-alertmanager\n namespace: monitor\n resourceVersion: "57106409"\n selfLink: \/apis\/monitoring.coreos.com\/v1\/namespaces\/monitor\/servicemonitors\/prometheus-kube-prometheus-alertmanager\n uid: 06d6df58-ebc5-4e6d-afd8-d551afe8ad4e\n spec:\n endpoints:\n - path: \/metrics\n port: web\n namespaceSelector:\n matchNames:\n - monitor \n selector: # \u8981\u76d1\u63a7\u7684 Endpoints \u5fc5\u987b\u5e26\u6709\u4ee5\u4e0b\u6807\u7b7e\u3002\n matchLabels:\n app: kube-prometheus-stack-alertmanager \n release: prometheus\n self-monitor: "true"<\/code><\/pre>\n
<\/p>\n
Alertmanager<\/strong><\/h2>\n
Alertmanager \u81ea\u5b9a\u4e49\u8d44\u6e90(CRD)\u58f0\u660e\u5728 Kubernetes \u96c6\u7fa4\u4e2d\u8fd0\u884c\u7684 Alertmanager \u7684\u671f\u671b\u8bbe\u7f6e\u3002\u5b83\u4e5f\u63d0\u4f9b\u4e86\u914d\u7f6e\u526f\u672c\u96c6\u548c\u6301\u4e45\u5316\u5b58\u50a8\u7684\u9009\u9879\u3002<\/p>\n
Alertmanager\u81ea\u5b9a\u4e49\u8d44\u6e90\u5728Kubernetes\u4e2d\u4ee5StatefulSet\u8fd0\u884c\u7531Operator\u521b\u5efa\u548cOperator\u540c\u4e00namespace\u3002<\/p>\n
Alertmanager Pod \u90fd\u4f1a\u6302\u8f7d\u4e00\u4e2a\u540d\u4e3a
\u7684 Secret\uff0c\u8be5Secret\u662f Alertmanager \u7684\u76f8\u5173\u914d\u7f6e\uff0cOperator \u6839\u636e\u76f8\u5173\u914d\u7f6e\u4f1a\u5b9e\u65f6\u66f4\u65b0\u76f8\u5173Secret\u3002<\/p>\n \u4e00\u4e2a\u6837\u4f8b\u914d\u7f6e\u5982\u4e0b\uff1a<\/p>\n
Alertmanager \u914d\u7f6e<\/a><\/p>\n
apiVersion: monitoring.coreos.com\/v1\n kind: Alertmanager #\u81ea\u5b9a\u4e49\u8d44\u6e90\n metadata:\n annotations:\n meta.helm.sh\/release-name: prometheus\n meta.helm.sh\/release-namespace: monitor\n creationTimestamp: "2021-04-19T08:12:34Z"\n generation: 2\n labels:\n app: kube-prometheus-stack-alertmanager\n app.kubernetes.io\/managed-by: Helm\n chart: kube-prometheus-stack-14.9.0\n heritage: Helm\n release: prometheus\n name: prometheus-kube-prometheus-alertmanager\n namespace: monitor\n resourceVersion: "57305495"\n selfLink: \/apis\/monitoring.coreos.com\/v1\/namespaces\/monitor\/alertmanagers\/prometheus-kube-prometheus-alertmanager\n uid: aa997233-0341-413f-adde-45746e43ccdc\n spec:\n alertmanagerConfigNamespaceSelector: {}\n alertmanagerConfigSelector: {}\n externalUrl: http:\/\/alertmanager-dev.rencaiyoujia.cn\/\n image: quay.io\/prometheus\/alertmanager:v0.21.0\n listenLocal: false\n logFormat: logfmt\n logLevel: info\n paused: false\n portName: web\n replicas: 1\n retention: 120h\n routePrefix: \/\n securityContext:\n fsGroup: 2000\n runAsGroup: 2000\n runAsNonRoot: true\n runAsUser: 1000\n serviceAccountName: prometheus-kube-prometheus-alertmanager\n version: v0.21.0\n<\/code><\/pre>\n
<\/p>\n
PrometheusRule<\/h2>\n
PrometheusRule CRD \u58f0\u660e\u4e00\u4e2a\u6216\u591a\u4e2a Prometheus \u5b9e\u4f8b\u9700\u8981\u7684 Prometheus rule\u3002<\/p>\n
Alerts \u548c recording rules \u53ef\u4ee5\u4fdd\u5b58\u5e76\u5e94\u7528\u4e3a yaml \u6587\u4ef6\uff0c\u53ef\u4ee5\u88ab\u52a8\u6001\u52a0\u8f7d\u800c\u4e0d\u9700\u8981\u91cd\u542f\u3002<\/p>\n
\u4e00\u4e2a\u6837\u4f8b\u914d\u7f6e\u5982\u4e0b\uff1a<\/p>\n
PrometheusRule \u914d\u7f6e<\/a><\/p>\n
apiVersion: monitoring.coreos.com\/v1\nkind: PrometheusRule #\u81ea\u5b9a\u4e49\u8d44\u6e90\nmetadata:\n labels: ## \u5fc5\u987b\u5e26\u6709\u4ee5\u4e0b\u6807\u7b7e\u624d\u80fd\u88abprometheus \u9009\u62e9\u5230\uff0c\u5728prometheus \u81ea\u5b9a\u4e49\u8d44\u6e90\u4e2d\u914d\u7f6e\u3002\n app: kube-prometheus-stack\n release: prometheus\n name: disk-free-rules\n namespace: monitor\nspec:\n groups:\n - name: disk\n rules: # \u5b9a\u4e49\u4e86\u4e00\u7ec4\u62a5\u8b66\u89c4\u5219\uff0c \n - alert: diskFree\n annotations:\n summary: "{{ $labels.job }} \u9879\u76ee\u5b9e\u4f8b {{ $labels.instance }} \u78c1\u76d8\u4f7f\u7528\u7387\u5927\u4e8e 80%"\n description: "{{ $labels.instance }} {{ $labels.mountpoint }} \u78c1\u76d8\u4f7f\u7528\u7387\u5927\u4e8e80% (\u5f53\u524d\u7684\u503c: {{ $value }}%),\u8bf7\u53ca\u65f6\u5904\u7406"\n expr: |\n (1-(node_filesystem_free_bytes{fstype=~"ext4|xfs",mountpoint!="\/boot"} \/ node_filesystem_size_bytes{fstype=~"ext4|xfs",mountpoint!="\/boot"}) )*100 > 85\n for: 3m\n labels:\n level: disaster\n severity: warning<\/code><\/pre>\n
<\/p>\n
Service<\/strong><\/h2>\n
\u8fd9\u91cc\u7684 Service \u5c31\u662f k8s Cluster \u4e2d\u7684 Service \u8d44\u6e90\uff0c\u4e5f\u662f Prometheus \u8981\u76d1\u63a7\u7684\u5bf9\u8c61\uff0c\u5728 Prometheus \u4e2d\u53eb\u505a Target\u3002\u6bcf\u4e2a\u76d1\u63a7\u5bf9\u8c61\u90fd\u6709\u4e00\u4e2a\u5bf9\u5e94\u7684 Service\u3002\u6bd4\u5982\u8981\u76d1\u63a7 Kubernetes Scheduler\uff0c\u5c31\u5f97\u6709\u4e00\u4e2a\u4e0e Scheduler \u5bf9\u5e94\u7684 Service\u3002\u5f53\u7136\uff0cKubernetes \u96c6\u7fa4\u9ed8\u8ba4\u662f\u6ca1\u6709\u8fd9\u4e2a Service \u7684\uff0cPrometheus Operator \u4f1a\u8d1f\u8d23\u521b\u5efa\u3002<\/p>\n
Service \u8d44\u6e90\u4e3b\u8981\u7528\u6765\u5bf9\u5e94 Kubernetes \u96c6\u7fa4\u4e2d\u7684 Metrics Server Pod\uff0c\u6765\u63d0\u4f9b\u7ed9 ServiceMonitor \u9009\u53d6\u8ba9 Prometheus Server \u6765\u83b7\u53d6\u4fe1\u606f\u3002\u7b80\u5355\u7684\u8bf4\u5c31\u662f Prometheus \u76d1\u63a7\u7684\u5bf9\u8c61\uff0c\u4f8b\u5982\u4e4b\u524d\u4e86\u89e3\u7684 Node Exporter Service\u3001Mysql Exporter Service \u7b49\u7b49\u3002<\/p>\n
<\/p>\n
Exporter<\/strong><\/h2>\n
Exporter\u662f\u670d\u52a1\u5668\u7aefagent\uff0c\u8d1f\u8d23\u91c7\u96c6\u4e3b\u673a\u7684\u8fd0\u884c\u6307\u6807\uff0c\u5178\u578b\u7684\u5305\u62ecCPU\u3001\u5185\u5b58\uff0c\u78c1\u76d8\u3001\u7f51\u7edc\u7b49\u7b49\u76d1\u63a7\u6837\u672c\u3002exporter\u7ec4\u4ef6\u8d1f\u8d23\u6536\u96c6\u8282\u70b9\u4e0a\u7684metrics\u76d1\u63a7\u6570\u636e\uff0c\u5e76\u5c06\u6570\u636e\u63a8\u9001\u7ed9prometheus server, \u6bd4\u5982node-export,mysql-export,blackbox-export \u7b49\u7b49\u3002\u67e5\u770b\u66f4\u591a<\/a><\/p>\n
Grafana<\/strong><\/h2>\n
Grafana\u662f\u53ef\u89c6\u5316\u6570\u636e\u7edf\u8ba1\u548c\u76d1\u63a7\u5e73\u53f0\u3002<\/p>\n
MetricServer<\/strong><\/h2>\n
MetricServer\u662fkubernetes\u96c6\u7fa4\u8d44\u6e90\u4f7f\u7528\u60c5\u51b5\u7684\u805a\u5408\u5668\uff0c\u6536\u96c6\u6570\u636e\u7ed9kubernetes\u96c6\u7fa4\u5185\u4f7f\u7528\uff0c\u5982kubectl,hpa,scheduler\u7b49\u3002<\/p>\n
KubeStateMetrics<\/strong><\/h2>\n
KubeStateMetrics\u6536\u96c6kubernetes\u96c6\u7fa4\u5185\u8d44\u6e90\u5bf9\u8c61\u6570\u636e\uff0c\u5236\u5b9a\u544a\u8b66\u89c4\u5219\u3002<\/p>\n
Operator\u662f\u6700\u6838\u5fc3\u7684\u90e8\u5206\uff0c\u4f5c\u4e3a\u4e00\u4e2a\u63a7\u5236\u5668\uff0c\u4ed6\u4f1a\u53bb\u521b\u5efaPrometheus\u3001ServiceMonitor\u3001AlertManager\u4ee5\u53caPrometheusRule 4\u4e2aCRD\u8d44\u6e90\u5bf9\u8c61\uff0c\u7136\u540e\u4f1a\u4e00\u76f4\u76d1\u63a7\u5e76\u7ef4\u6301\u8fd94\u4e2a\u8d44\u6e90\u5bf9\u8c61\u7684\u72b6\u6001\u3002<\/p>\n
\u5176\u4e2d\u521b\u5efa\u7684prometheus\u8fd9\u79cd\u8d44\u6e90\u5bf9\u8c61\u5c31\u662f\u4f5c\u4e3aPrometheus Server\u5b58\u5728\uff0c\u800cServiceMonitor\u5c31\u662fexporter\u7684\u5404\u79cd\u62bd\u8c61\uff0cexporter\u662f\u7528\u6765\u63d0\u4f9b\u4e13\u95e8\u63d0\u4f9bmetrics\u6570\u636e\u63a5\u53e3\u7684\u5de5\u5177\uff0cPrometheus\u5c31\u662f\u901a\u8fc7ServiceMonitor\u63d0\u4f9b\u7684metrics\u6570\u636e\u63a5\u53e3\u53bb pull \u6570\u636e\u7684\uff0c\u5f53\u7136alertmanager\u8fd9\u79cd\u8d44\u6e90\u5bf9\u8c61\u5c31\u662f\u5bf9\u5e94\u7684AlertManager\u7684\u62bd\u8c61\uff0c\u800cPrometheusRule\u662f\u7528\u6765\u88abPrometheus\u5b9e\u4f8b\u4f7f\u7528\u7684\u62a5\u8b66\u89c4\u5219\u6587\u4ef6\u3002<\/p>\n
\u8fd9\u6837\u6211\u4eec\u8981\u5728\u96c6\u7fa4\u4e2d\u76d1\u63a7\u4ec0\u4e48\u6570\u636e\uff0c\u5c31\u53d8\u6210\u4e86\u76f4\u63a5\u53bb\u64cd\u4f5c Kubernetes \u96c6\u7fa4\u7684\u8d44\u6e90\u5bf9\u8c61\u4e86\uff0c\u662f\u4e0d\u662f\u65b9\u4fbf\u5f88\u591a\u4e86\u3002\u4e0a\u56fe\u4e2d\u7684 Service \u548c ServiceMonitor \u90fd\u662f Kubernetes \u7684\u8d44\u6e90\uff0c\u4e00\u4e2a ServiceMonitor \u53ef\u4ee5\u901a\u8fc7 labelSelector \u7684\u65b9\u5f0f\u53bb\u5339\u914d\u4e00\u7c7b Service\uff0cPrometheus \u4e5f\u53ef\u4ee5\u901a\u8fc7 labelSelector \u53bb\u5339\u914d\u591a\u4e2aServiceMonitor\u3002<\/p>\n
\u5b83\u4eec\u4e4b\u95f4\u7684\u5173\u7cfb\u5982\u4e0b\u56fe\uff1a<\/p>\n
<\/p>\n
\n\u53c2\u8003:<\/h2>\n
prometheus-community\/helm-charts<\/strong><\/a><\/p>\n
Prometheus Operator \u8bbe\u8ba1\u6587\u6863<\/strong><\/a><\/p>\n