关于kubernetes:30kubernetesk8s笔记-Promethues一-部署安装

1次阅读

共计 5931 个字符,预计需要花费 15 分钟才能阅读完成。

Promethues 官网:
Prometheus 介绍

一、Prometheus 介绍

Prometheus 是一个开源的系统监控和报警零碎,当初曾经退出到 CNCF 基金会,成为继 k8s 之后第二个在 CNCF 托管的我的项目,在 kubernetes 容器管理系统中,通常会搭配 prometheus 进行监控,同时也反对多种 exporter 采集数据,还反对 pushgateway 进行数据上报,Prometheus 性能足够撑持上万台规模的集群。

二、Prometheus 特点

2.1、prometheus 特点
1)多维度数据模型

每一个工夫序列数据都由 metric 度量指标名称和它的标签 labels 键值对汇合惟一确定:这个 metric 度量指标名称指定监控指标零碎的测量特色(如:http_requests_total- 接管 http 申请的总计数)。labels 开启了 Prometheus 的多维数据模型:对于雷同的度量名称,通过不同标签列表的联合, 会造成特定的度量维度实例。(例如:所有蕴含度量名称为 /api/tracks 的 http 申请,打上 method=POST 的标签,则造成了具体的 http 申请)。这个查询语言在这些度量和标签列表的根底上进行过滤和聚合。扭转任何度量上的任何标签值,则会造成新的工夫序列图。

2)灵便的查询语言(PromQL):能够对采集的 metrics 指标进行加法,乘法,连贯等操作;

3)能够间接在本地部署,不依赖其余分布式存储;

4)通过基于 HTTP 的 pull 形式采集时序数据;

5)能够通过两头网关 pushgateway 的形式把工夫序列数据推送到 prometheus server 端;

6)可通过服务发现或者动态配置来发现指标服务对象(targets)。

7)有多种可视化图像界面,如 Grafana 等。

8)高效的存储,每个采样数据占 3.5 bytes 左右,300 万的工夫序列,30s 距离,保留 60 天,耗费磁盘大略 200G。

9)做高可用,能够对数据做异地备份,联邦集群,部署多套 prometheus,pushgateway 上报数据

2.2、什么是样本
样本:在工夫序列中的每一个点称为一个样本(sample),样本由以下三局部组成:

指标(metric):指标名称和形容以后样本特色的 labelsets;
工夫戳(timestamp):一个准确到毫秒的工夫戳;
样本值(value):一个 folat64 的浮点型数据表示以后样本的值。
示意形式:通过如下表达方式示意指定指标名称和指定标签汇合的工夫序列:<metric name>{<label name>=<label value>, ...}

例如,指标名称为 api_http_requests_total,标签为 method=”POST” 和 handler=”/messages” 的工夫序列能够示意为:api_http_requests_total{method="POST", handler="/messages"}

Metric 类型:

Counter: 一种累加的 metric,如申请的个数,完结的工作数,呈现的谬误数等

Gauge: 惯例的 metric, 如温度,可任意加减。其为刹时的,与工夫没有关系的,能够任意变动的数据。

Histogram: 柱状图,用于察看后果采样,分组及统计,如:申请持续时间,响应大小。其次要用于示意一段时间内对数据的采样,并可能对其指定区间及总数进行统计。依据统计区间计算

Summary: 相似 Histogram,用于示意一段时间内数据采样后果,其间接存储 quantile 数据,而不是依据统计区间计算出来的。不须要计算,间接存储后果

PromQL 根本应用
PromQL (Prometheus Query Language) 是 Prometheus 本人开发的数据查问 DSL 语言,语言表现力十分丰盛,内置函数很多,在日常数据可视化以及 rule 告警中都会应用到它。在前面章节会介绍

更多请参见详情

三、Prometheus 组件介绍

1)Prometheus Server: 用于收集和存储工夫序列数据。

2)Client Library: 客户端库,检测利用程序代码,当 Prometheus 抓取实例的 HTTP 端点时,客户端库会将所有跟踪的 metrics 指标的以后状态发送到 prometheus server 端。

3)Exporters: prometheus 反对多种 exporter,通过 exporter 能够采集 metrics 数据,而后发送到 prometheus server 端,所有向 promtheus server 提供监控数据的程序都能够被称为 exporter

4)Alertmanager: 从 Prometheus server 端接管到 alerts 后,会进行去重,分组,并路由到相应的接管方,发出报警,常见的接管形式有:电子邮件,微信,钉钉, slack 等。

5)Grafana:监控仪表盘,可视化监控数据

6)pushgateway: 各个指标主机可上报数据到 pushgateway,而后 prometheus server 对立从 pushgateway 拉取数据。

helm 部署 prometheus

从官网仓库搜寻 prometheus 并按提醒增加仓库并装置

https://artifacthub.io/

  • 增加仓库
[root@k8s-master prometheus]# helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
"prometheus-community" has been added to your repositories

[root@k8s-master prometheus]# helm repo update  #更新仓库
Hang tight while we grab the latest from your chart repositories...
...Successfully got an update from the "bitnami" chart repository
...Successfully got an update from the "prometheus-community" chart repository
...Successfully got an update from the "stable" chart repository
Update Complete. ⎈Happy Helming!⎈

[root@k8s-master prometheus]# helm search repo prometheus
NAME                                                  CHART VERSION    APP VERSION    DESCRIPTION                                       
bitnami/kube-prometheus                               6.1.8            0.50.0         kube-prometheus collects Kubernetes manifests t...
bitnami/prometheus-operator                           0.31.1           0.41.0         DEPRECATED The Prometheus Operator for Kubernet...
bitnami/wavefront-prometheus-storage-adapter          1.0.7            1.0.3          Wavefront Storage Adapter is a Prometheus integ...
prometheus-community/kube-prometheus-stack            18.0.10          0.50.0         kube-prometheus-stack collects Kubernetes manif...
prometheus-community/prometheus                       14.6.1           2.26.0         Prometheus is a monitoring system and time seri...
prometheus-community/prometheus-adapter               2.17.0           v0.9.0         A Helm chart for k8s prometheus adapter           
prometheus-community/prometheus-blackbox-exporter     5.0.3            0.19.0         Prometheus Blackbox Exporter  


[root@k8s-master prometheus]#  helm show readme  prometheus-community/prometheus   #装置前看下蕴含的组件是否适合 此版本蕴含的插件比拟全面

[root@k8s-master prometheus]# kubectl create ns monitor
namespace/monitor created
  • 下载 Chart 包 依据本人需要批改values.yaml
[root@k8s-master prometheus]#  helm pull prometheus-community/prometheus
[root@k8s-master prometheus]# ls
prometheus-14.6.1.tgz 
[root@k8s-master prometheus]# tar -xf prometheus-14.6.1.tgz 
[root@k8s-master prometheus]# cd prometheus/
[root@k8s-master prometheus]# ls
Chart.lock  charts  Chart.yaml  README.md  templates  values.yaml
  • prometheus-serverprometheus-alertmanager两个字段 PVC 勾销掉 正式环境须要先
    部署 PVC 存储卷
[root@k8s-master prometheus]# vim values.yaml  

 persistentVolume:
    ## If true, alertmanager will create/use a Persistent Volume Claim
    ## If false, use emptyDir
    ##
    enabled: false  #批改为 false

#配置 prometheus、alertmanager  ingress hosts
ingress:
    ## If true, pushgateway Ingress will be created
    ##
    enabled: true
    ingressClassName: nginx   #存在多个 ingress 指定应用 ingress-nginx

    hosts: 
        - prometheus.com
...
    hosts:
        - alertmanager.com
  • 部署装置
[root@k8s-master prometheus]#  helm install prometheus  prometheus  -n monitor
NAME: prometheus
LAST DEPLOYED: Sat Sep 18 15:40:47 2021
NAMESPACE: monitor
STATUS: deployed
REVISION: 1
TEST SUITE: None
NOTES:
The Prometheus server can be accessed via port 80 on the following DNS name from within your cluster:
prometheus-server.monitor.svc.cluster.local

[root@k8s-master prometheus]# kubectl get pod  -n monitor
NAME                                             READY   STATUS    RESTARTS   AGE
prometheus-alertmanager-769488c787-h9s7z         2/2     Running   0          2d21h
prometheus-kube-state-metrics-68b6c8b5c5-fgqjg   1/1     Running   0          2d21h
prometheus-node-exporter-hfw4c                   1/1     Running   0          2d21h
prometheus-node-exporter-rzjzj                   1/1     Running   0          2d21h
prometheus-node-exporter-vhr9p                   1/1     Running   0          2d21h
prometheus-pushgateway-8655bf87b9-xwzjx          1/1     Running   0          2d21h
prometheus-server-7df4f9b485-7pz8j               2/2     Running   0          2d21h

[root@k8s-master prometheus]# kubectl get svc -n monitor
NAME                            TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)    AGE
prometheus-alertmanager         ClusterIP   10.96.135.142    <none>        80/TCP     2d21h
prometheus-kube-state-metrics   ClusterIP   10.96.153.83     <none>        8080/TCP   2d21h
prometheus-node-exporter        ClusterIP   None             <none>        9100/TCP   2d21h
prometheus-pushgateway          ClusterIP   10.109.40.211    <none>        9091/TCP   2d21h
prometheus-server               ClusterIP   10.104.231.248   <none>        80/TCP     2d21h

[root@k8s-master prometheus]# kubectl get ingress -n monitor
NAME                      CLASS   HOSTS              ADDRESS           PORTS   AGE
prometheus-alertmanager   nginx   alertmanager.com   192.168.103.211   80      2d21h
prometheus-server         nginx   prometheus.com     192.168.103.211   80      2d21h

[root@k8s-master prometheus]# kubectl get svc -n ingress-nginx
NAME                                 TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)                      AGE
ingress-nginx-controller             NodePort    10.108.78.161    <none>        80:32601/TCP,443:31371/TCP   85d
ingress-nginx-controller-admission   ClusterIP   10.101.146.205   <none>        443/TCP                      85d
  • 拜访主机增加 hosts
    192.168.103.211 prometheus.com
  • 关上浏览器拜访 prometheus http://prometheus.com:32601
正文完
 0