prometheus监控安装

一、监控方案

  • Cadvisor + node-exporter + prometheus + grafana

    数据采集 ——> 汇总 ——> 处理、存储 ——> 展示

二、监控流程

Prometheus使用cadvisor采集容器监控指标,而cadvisor集成在K8S的kubelet中所以无需部署,通过Prometheus进程存储,使用grafana进行展示

node节点监控

​ node端的监控通过node_exporter采集当前主机的资源,通过Prometheus进程存储,最后使用grafana进行展示

master节点监控

​ master的监控通过kube-state-metrics插件从K8S获取到apiserver的相关数据并通过网页页面暴露出来,然后通过Prometheus进程存储,最后使用grafana进行展示

三、Kubernetes监控指标

K8S本身的监控指标
  1. node的资源利用率:监控node节点上的cpu、内存、硬盘等硬件资源
  2. node的数量:监控node数量与资源利用率、业务负载的比例情况,对成本、资源扩展进行评估
  3. pod的数量:监控当负载到一定程度时,node与pod的数量。评估负载到哪个阶段,大约需要多少服务器,以及每个pod的资源占用率,然后进行整体评估
  4. 资源对象状态:在K8S运行过程中,会创建很多pod、控制器、任务等,这些内容都是由K8S中的资源对象进行维护,所以我们可以对资源对象进行监控,获取资源对象的状态
Pod的监控
  1. 每个项目中pod的数量:分别监控正常、有问题的pod数量
  2. 容器资源利用率:统计当前pod的资源利用率,统计pod中的容器资源利用率,结合cpu、网络、内存进行评估
  3. 应用程序:监控项目中程序的自身情况,例如并发、请求响应等
监控指标 具体实现 案例
Pod性能 cadvisor 容器的CPU、内存利用率
Node性能 node-exporter node节点的CPU、内存利用率
K8S资源对象 kube-state-metrics pod、deployment、service

四、使用Prometheus监控Kubernetes

1.部署前准备

​ 在所有节点提前下载镜像

docker pull prom/node-exporter
docker pull prom/prometheus
docker pull grafana/grafana
2.安装
kubectl apply -f prometheus/

3.指定命令空间

kubectl create ns prometheus

五、yaml文件内容

(1)node-exporter.yaml
---
apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: node-exporter
  namespace: prometheus
  labels:
    k8s-app: node-exporter
spec:
  selector:
    matchLabels:
      k8s-app: node-exporter
  template:
    metadata:
      labels:
        k8s-app: node-exporter
    spec:
      containers:
      - image: prom/node-exporter
        name: node-exporter
        ports:
        - containerPort: 9100
          protocol: TCP
          name: http
---
apiVersion: v1
kind: Service
metadata:
  labels:
    k8s-app: node-exporter
  name: node-exporter
  namespace: prometheus
spec:
  ports:
  - name: http
    port: 9100
    nodePort: 31672
    protocol: TCP
  type: NodePort
  selector:
    k8s-app: node-exporter

(2)rbac-setup.yaml
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: prometheus
  namespace: prometheus
rules:
- apiGroups: [""]
  resources:
  - nodes
  - nodes/proxy
  - services
  - endpoints
  - pods
  verbs: ["get", "list", "watch"]
- apiGroups:
  - extensions
  resources:
  - ingresses
  verbs: ["get", "list", "watch"]
- nonResourceURLs: ["/metrics"]
  verbs: ["get"]
---
apiVersion: v1
kind
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值