• helm部署prometheus


    组件说明:

    1.MetricServer:是kubernetes集群资源使用情况的聚合器,收集数据给kubernetes集群内使用,如kubectl,hpa,scheduler等

    2.prometheusOperator:是一个系统监测和警报工具箱,用来存储监控数据。

    3.NodeExporter:用于各Node的关键度量指标状态数据

    4.KubeStateMetrics:收集kubernetes集群内资源对象数据,制定告警规则

    5.Prometheus:采集pull方式收集apiserver,scheduler,controller-manager,kubelet组件数据,通过Http协议传输

    6.Grafana:是可视化数据统计和监控平台。

    [root@k8s-master01 ~]# mkdir prometheus
    [root@k8s-master01 ~]# cd prometheus/
    [root@k8s-master01 prometheus]# 

    Git下项目

    [root@k8s-master01 prometheus]# git clone https://github.com/coreos/kube-prometheus.git
    正克隆到 'kube-prometheus'...
    remote: Enumerating objects: 12120, done.
    remote: Counting objects: 100% (871/871), done.
    remote: Compressing objects: 100% (319/319), done.
    remote: Total 12120 (delta 515), reused 731 (delta 461), pack-reused 11249
    接收对象中: 100% (12120/12120), 6.13 MiB | 3.02 MiB/s, done.
    处理 delta 中: 100% (7480/7480), done.

    到yaml文件的模板目录

    [root@k8s-master01 prometheus]# cd kube-prometheus/manifests/
    [root@k8s-master01 manifests]# 

    修改 grafana-service.yaml 文件,使用 nodepode 方式访问 grafana:

    apiVersion: v1
    kind: Service
    metadata:
      labels:
        app.kubernetes.io/component: grafana
        app.kubernetes.io/name: grafana
        app.kubernetes.io/part-of: kube-prometheus
        app.kubernetes.io/version: 7.5.4
      name: grafana
      namespace: monitoring
    spec:
      #增加NodePort访问方式
      type: NodePort
      ports:
      - name: http
        port: 3000
        targetPort: http
        #增加端口
        nodePort: 30100
      selector:
        app.kubernetes.io/component: grafana
        app.kubernetes.io/name: grafana
        app.kubernetes.io/part-of: kube-prometheus

    修改prometheus-service.yaml

    apiVersion: v1
    kind: Service
    metadata:
      labels:
        app.kubernetes.io/component: prometheus
        app.kubernetes.io/name: prometheus
        app.kubernetes.io/part-of: kube-prometheus
        app.kubernetes.io/version: 2.26.0
        prometheus: k8s
      name: prometheus-k8s
      namespace: monitoring
    spec:
      type: NodePort
      ports:
      - name: web
        port: 9090
        targetPort: web
        nodePort: 30200
      selector:
        app: prometheus
        app.kubernetes.io/component: prometheus
        app.kubernetes.io/name: prometheus
        app.kubernetes.io/part-of: kube-prometheus
        prometheus: k8s
      sessionAffinity: ClientIP

    修改alertmanager-service.yaml

    apiVersion: v1
    kind: Service
    metadata:
      labels:
        alertmanager: main
        app.kubernetes.io/component: alert-router
        app.kubernetes.io/name: alertmanager
        app.kubernetes.io/part-of: kube-prometheus
        app.kubernetes.io/version: 0.21.0
      name: alertmanager-main
      namespace: monitoring
    spec:
      type: NodePort
      ports:
      - name: web
        port: 9093
        targetPort: web
        nodePort: 30300
      selector:
        alertmanager: main
        app: alertmanager
        app.kubernetes.io/component: alert-router
        app.kubernetes.io/name: alertmanager
        app.kubernetes.io/part-of: kube-prometheus
      sessionAffinity: ClientIP

    [root@k8s-master01 manifests]# kubectl apply -f ../manifests/

    多执行2遍可能有依赖

    [root@k8s-master01 manifests]# kubectl get pod -n monitoring
    NAME                                   READY   STATUS    RESTARTS   AGE
    alertmanager-main-0                    2/2     Running   0          5m59s
    alertmanager-main-1                    2/2     Running   0          5m43s
    alertmanager-main-2                    2/2     Running   0          5m20s
    grafana-7dc5f8f9f6-prwwk               1/1     Running   0          6m2s
    kube-state-metrics-5cbd67455c-ppqbx    4/4     Running   0          5m39s
    node-exporter-6s9dz                    2/2     Running   0          5m57s
    node-exporter-jgmsz                    2/2     Running   0          5m57s
    node-exporter-swhz5                    2/2     Running   0          5m57s
    prometheus-adapter-668748ddbd-qmtdc    1/1     Running   0          5m53s
    prometheus-k8s-0                       3/3     Running   1          5m48s
    prometheus-k8s-1                       3/3     Running   1          5m48s
    prometheus-operator-7447bf4dcb-xsb4b   1/1     Running   0          6m17s
    [root@k8s-master01 manifests]# 

    top查看下状态

    [root@k8s-master01 manifests]# kubectl top node
    NAME           CPU(cores)   CPU%   MEMORY(bytes)   MEMORY%   
    k8s-master01   818m         20%    1741Mi          22%       
    k8s-node01     180m         4%     1174Mi          15%       
    k8s-node02     175m         4%     1196Mi          15%       

    访问 prometheus


    prometheus 对应的 nodeport 端口为 30200,访问http://MasterIP:30200

     通过访问http://MasterIP:30200/target可以看到 prometheus 已经成功连接上了 k8s apiserver

    访问 grafana


    grafana 的端口号是 30100,浏览器访问http://MasterIP:30100用户名密码默认 admin/admin

     添加数据源 grafana 默认已经添加了 Prometheus 数据源,grafana 支持多种时序数据源,每种数据源都有各自的查询编辑器

     

     test测试一下

     导入一些模板

     然后去Home下查下数据

     

  • 相关阅读:
    C语言的setlocale和localtime函数(C++也可用)
    stdlib.h,string.h,wchar.h的函数列表(cplusplus.com就有,很清楚)goodx
    DataSet与JSON互转
    21 步助你成为成功的 Web 开发者(激情不是被动的:它是一种对行动起来的追求)
    开发人员与非技术同事沟通的七个聪明策略
    页面架构
    可视化配置以及Net应用MemCache在win7
    NPOI以及在ASP.NET MVC中的使用
    TCP/IP协议
    springMVC+angular+bootstrap+mysql的简易购物网站搭建
  • 原文地址:https://www.cnblogs.com/tian880820/p/14827753.html
Copyright © 2020-2023  润新知