Kubernetes實戰總結 - Prometheus部署(v0.3.0)


什么是普羅米修斯?

Prometheus是最初在SoundCloud上構建的開源系統監視和警報工具包 。

自2012年成立以來,許多公司和組織都采用了Prometheus,該項目擁有非常活躍的開發人員和用戶社區。

 

組件說明

  • Prometheus負責實現對K8s集群監控數據的獲取,存儲以及查詢。
  • PrometheusOperator為Prometheus實例的部署和管理提供了簡單的監視定義。
  • KubeStateMetrics是K8s集群資源使用情況的聚合器,收集數據給K8s集群內使用(如HPA)。
  • AlertManager負責將告警信息重復數據刪除,分組和路由到正確的接收者集成。
  • NodeExporter用於采集集群中各個節點的資源使用情況。
  • Grafana一個跨平台的開源的度量分析和可視化工具。

 

系統架構

普羅米修斯建築

 


什么時候合適?

Prometheus非常適合記錄任何純數字時間序列。

它既適合以機器為中心的監視,也適合於高度動態的面向服務的體系結構的監視。在微服務世界中,它對多維數據收集和查詢的支持是一種特別的優勢。

Prometheus的設計旨在提高可靠性,使其成為中斷期間要使用的系統,以使您能夠快速診斷問題。

每個Prometheus服務器都是獨立的,而不依賴於網絡存儲或其他遠程服務。當基礎結構的其他部分損壞時,您可以依靠它,並且無需設置廣泛的基礎結構即可使用它。

什么時候不合適?

普羅米修斯重視可靠性。即使在故障情況下,您始終可以查看有關系統的可用統計信息。

如果您需要100%的准確性(例如按請求計費),則Prometheus並不是一個不錯的選擇,因為所收集的數據可能不會足夠詳細和完整。

在這種情況下,最好使用其他系統來收集和分析數據以進行計費,並使用Prometheus進行其余的監視。

 

 


部署安裝

  Github : https://github.com/coreos/kube-prometheus

  1、下載官方源碼文件(默認鏡像源來自quay.io)

  wget -o kube-prometheus.tgz https://github.com/coreos/kube-prometheus/archive/v0.3.0.tar.gz

  •  當然,如果你的國外網不太友好,也可以下載本人百度雲文件(已修改鏡像源到aliyuncs)kube-prometheus-0.3.0.zip(ccer )

 

  2、解壓並部署安裝

  tar -zxvf kube-prometheus.tgz && cd kube-prometheus-0.3.0/manifests

  kubectl create -f setup

  until kubectl get servicemonitors --all-namespaces ; do date; sleep 1; echo ""; done

  kubectl create -f .

[root@k8s-32 manifests]# ls -R
.:
alertmanager-alertmanager.yaml              kube-state-metrics-service.yaml                             prometheus-clusterRole.yaml
alertmanager-secret.yaml                    node-exporter-clusterRoleBinding.yaml                       prometheus-operator-serviceMonitor.yaml
alertmanager-serviceAccount.yaml            node-exporter-clusterRole.yaml                              prometheus-prometheus.yaml
alertmanager-serviceMonitor.yaml            node-exporter-daemonset.yaml                                prometheus-roleBindingConfig.yaml
alertmanager-service.yaml                   node-exporter-serviceAccount.yaml                           prometheus-roleBindingSpecificNamespaces.yaml
grafana-dashboardDatasources.yaml           node-exporter-serviceMonitor.yaml                           prometheus-roleConfig.yaml
grafana-dashboardDefinitions.yaml           node-exporter-service.yaml                                  prometheus-roleSpecificNamespaces.yaml
grafana-dashboardSources.yaml               prometheus-adapter-apiService.yaml                          prometheus-rules.yaml
grafana-deployment.yaml                     prometheus-adapter-clusterRoleAggregatedMetricsReader.yaml  prometheus-serviceAccount.yaml
grafana-serviceAccount.yaml                 prometheus-adapter-clusterRoleBindingDelegator.yaml         prometheus-serviceMonitorApiserver.yaml
grafana-serviceMonitor.yaml                 prometheus-adapter-clusterRoleBinding.yaml                  prometheus-serviceMonitorCoreDNS.yaml
grafana-service.yaml                        prometheus-adapter-clusterRoleServerResources.yaml          prometheus-serviceMonitorKubeControllerManager.yaml
kube-state-metrics-clusterRoleBinding.yaml  prometheus-adapter-clusterRole.yaml                         prometheus-serviceMonitorKubelet.yaml
kube-state-metrics-clusterRole.yaml         prometheus-adapter-configMap.yaml                           prometheus-serviceMonitorKubeScheduler.yaml
kube-state-metrics-deployment.yaml          prometheus-adapter-deployment.yaml                          prometheus-serviceMonitor.yaml
kube-state-metrics-roleBinding.yaml         prometheus-adapter-roleBindingAuthReader.yaml               prometheus-service.yaml
kube-state-metrics-role.yaml                prometheus-adapter-serviceAccount.yaml                      setup
kube-state-metrics-serviceAccount.yaml      prometheus-adapter-service.yaml
kube-state-metrics-serviceMonitor.yaml      prometheus-clusterRoleBinding.yaml

./setup:
0namespace-namespace.yaml                                       prometheus-operator-0prometheusruleCustomResourceDefinition.yaml  prometheus-operator-deployment.yaml
prometheus-operator-0alertmanagerCustomResourceDefinition.yaml  prometheus-operator-0servicemonitorCustomResourceDefinition.yaml  prometheus-operator-serviceAccount.yaml
prometheus-operator-0podmonitorCustomResourceDefinition.yaml    prometheus-operator-clusterRoleBinding.yaml                       prometheus-operator-service.yaml
prometheus-operator-0prometheusCustomResourceDefinition.yaml    prometheus-operator-clusterRole.yaml
ls -R
[root@k8s-32 manifests]# kubectl create -f setup/.
namespace/monitoring created
customresourcedefinition.apiextensions.k8s.io/alertmanagers.monitoring.coreos.com created
customresourcedefinition.apiextensions.k8s.io/podmonitors.monitoring.coreos.com created
customresourcedefinition.apiextensions.k8s.io/prometheuses.monitoring.coreos.com created
customresourcedefinition.apiextensions.k8s.io/prometheusrules.monitoring.coreos.com created
customresourcedefinition.apiextensions.k8s.io/servicemonitors.monitoring.coreos.com created
clusterrole.rbac.authorization.k8s.io/prometheus-operator created
clusterrolebinding.rbac.authorization.k8s.io/prometheus-operator created
deployment.apps/prometheus-operator created
service/prometheus-operator created
serviceaccount/prometheus-operator created
[root@k8s-32 manifests]# kubectl create -f .
alertmanager.monitoring.coreos.com/main created
secret/alertmanager-main created
service/alertmanager-main created
serviceaccount/alertmanager-main created
servicemonitor.monitoring.coreos.com/alertmanager created
secret/grafana-datasources created
configmap/grafana-dashboard-apiserver created
configmap/grafana-dashboard-cluster-total created
configmap/grafana-dashboard-controller-manager created
configmap/grafana-dashboard-k8s-resources-cluster created
configmap/grafana-dashboard-k8s-resources-namespace created
configmap/grafana-dashboard-k8s-resources-node created
configmap/grafana-dashboard-k8s-resources-pod created
configmap/grafana-dashboard-k8s-resources-workload created
configmap/grafana-dashboard-k8s-resources-workloads-namespace created
configmap/grafana-dashboard-kubelet created
configmap/grafana-dashboard-namespace-by-pod created
configmap/grafana-dashboard-namespace-by-workload created
configmap/grafana-dashboard-node-cluster-rsrc-use created
configmap/grafana-dashboard-node-rsrc-use created
configmap/grafana-dashboard-nodes created
configmap/grafana-dashboard-persistentvolumesusage created
configmap/grafana-dashboard-pod-total created
configmap/grafana-dashboard-pods created
configmap/grafana-dashboard-prometheus-remote-write created
configmap/grafana-dashboard-prometheus created
configmap/grafana-dashboard-proxy created
configmap/grafana-dashboard-scheduler created
configmap/grafana-dashboard-statefulset created
configmap/grafana-dashboard-workload-total created
configmap/grafana-dashboards created
deployment.apps/grafana created
service/grafana created
serviceaccount/grafana created
servicemonitor.monitoring.coreos.com/grafana created
clusterrole.rbac.authorization.k8s.io/kube-state-metrics created
clusterrolebinding.rbac.authorization.k8s.io/kube-state-metrics created
deployment.apps/kube-state-metrics created
role.rbac.authorization.k8s.io/kube-state-metrics created
rolebinding.rbac.authorization.k8s.io/kube-state-metrics created
service/kube-state-metrics created
serviceaccount/kube-state-metrics created
servicemonitor.monitoring.coreos.com/kube-state-metrics created
clusterrole.rbac.authorization.k8s.io/node-exporter created
clusterrolebinding.rbac.authorization.k8s.io/node-exporter created
daemonset.apps/node-exporter created
service/node-exporter created
serviceaccount/node-exporter created
servicemonitor.monitoring.coreos.com/node-exporter created
apiservice.apiregistration.k8s.io/v1beta1.metrics.k8s.io created
clusterrole.rbac.authorization.k8s.io/prometheus-adapter created
clusterrole.rbac.authorization.k8s.io/system:aggregated-metrics-reader created
clusterrolebinding.rbac.authorization.k8s.io/prometheus-adapter created
clusterrolebinding.rbac.authorization.k8s.io/resource-metrics:system:auth-delegator created
clusterrole.rbac.authorization.k8s.io/resource-metrics-server-resources created
configmap/adapter-config created
deployment.apps/prometheus-adapter created
rolebinding.rbac.authorization.k8s.io/resource-metrics-auth-reader created
service/prometheus-adapter created
serviceaccount/prometheus-adapter created
clusterrole.rbac.authorization.k8s.io/prometheus-k8s created
clusterrolebinding.rbac.authorization.k8s.io/prometheus-k8s created
servicemonitor.monitoring.coreos.com/prometheus-operator created
prometheus.monitoring.coreos.com/k8s created
rolebinding.rbac.authorization.k8s.io/prometheus-k8s-config created
rolebinding.rbac.authorization.k8s.io/prometheus-k8s created
rolebinding.rbac.authorization.k8s.io/prometheus-k8s created
rolebinding.rbac.authorization.k8s.io/prometheus-k8s created
role.rbac.authorization.k8s.io/prometheus-k8s-config created
role.rbac.authorization.k8s.io/prometheus-k8s created
role.rbac.authorization.k8s.io/prometheus-k8s created
role.rbac.authorization.k8s.io/prometheus-k8s created
prometheusrule.monitoring.coreos.com/prometheus-k8s-rules created
service/prometheus-k8s created
serviceaccount/prometheus-k8s created
servicemonitor.monitoring.coreos.com/prometheus created
servicemonitor.monitoring.coreos.com/kube-apiserver created
servicemonitor.monitoring.coreos.com/coredns created
servicemonitor.monitoring.coreos.com/kube-controller-manager created
servicemonitor.monitoring.coreos.com/kube-scheduler created
servicemonitor.monitoring.coreos.com/kubelet created
kubectl create -f .

 

  3、等待部署完成

 kubectl get pod -n monitoring

NAME                                   READY   STATUS    RESTARTS   AGE
alertmanager-main-0                    2/2     Running   0          65m
alertmanager-main-1                    2/2     Running   0          65m
alertmanager-main-2                    2/2     Running   0          65m
grafana-7c54b4677d-btwfb               1/1     Running   0          65m
kube-state-metrics-58b656b699-p8m29    3/3     Running   0          65m
node-exporter-rc5mx                    2/2     Running   0          65m
node-exporter-vdzkb                    2/2     Running   0          65m
node-exporter-xzdw2                    2/2     Running   0          65m
prometheus-adapter-7d6f96974c-76m4z    1/1     Running   0          65m
prometheus-k8s-0                       3/3     Running   1          65m
prometheus-k8s-1                       3/3     Running   1          65m
prometheus-operator-5bd99d6457-89n7h   1/1     Running   0          66m

 

 

  4、更改訪問模式(ClusterIP => NodePort)

    1)Prometheus

    kubectl edit svc/prometheus-k8s -n monitoring

    2)Alert Manager

    kubectl edit svc/alertmanager-main -n monitoring

    3)Grafana

    kubectl edit svc/grafana -n monitoring

 

  5、訪問MasterIP:Port,其中Grafana默認用戶名和密碼都是admin

    

    >>> 普羅米修斯功能強大,目前我也還沒有完全掌握,具體應用還需要大家自己深度學習。 

 

作者:Leozhanggg

出處:https://www.cnblogs.com/leozhanggg/p/12661566.html

本文版權歸作者和博客園共有,歡迎轉載,但未經作者同意必須保留此段聲明,且在文章頁面明顯位置給出原文連接,否則保留追究法律責任的權利。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM