Prometheus部署

Prometheus
相关地址信息
Prometheus github 地址:https://github.com/coreos/kube-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-master ~]# mkdir prometheus
[root@k8s-master ~]# cd prometheus
[root@k8s-master prometheus]# pwd
/root/prometheus

[root@k8s-master prometheus]# git clone https://github.com/coreos/kube-prometheus.git
Cloning into 'kube-prometheus'...
remote: Enumerating objects: 46, done.
remote: Counting objects: 100% (46/46), done.
remote: Compressing objects: 100% (27/27), done.
remote: Total 9714 (delta 21), reused 25 (delta 15), pack-reused 9668
Receiving objects: 100% (9714/9714), 5.34 MiB | 123.00 KiB/s, done.
Resolving deltas: 100% (5943/5943), done.

将kube-prometheus传到/root/下
[root@k8s-master ~]# cd /root/kube-prometheus/manifests

[root@k8s-master manifests]# vi grafana-service.yaml
Prometheus部署

[root@k8s-master manifests]# vi prometheus-service.yaml
Prometheus部署

[root@k8s-master manifests]# vi alertmanager-service.yaml
Prometheus部署

[root@k8s-master prometheus]# pwd
/root/
导入镜像
kube-prometheus.git.tar.gz prometheus.tar.gz load-images.sh

[root@k8s-master prometheus]# tar -zvxf prometheus.tar.gz
prometheus/
prometheus/addon-resizer.tar
prometheus/alertmanager.tar
prometheus/configmap-reload.tar
prometheus/grafana.tar
prometheus/k8s-prometheus-adapter-amd64.tar
prometheus/kube-rbac-proxy.tar
prometheus/kube-state-metrics.tar
prometheus/node-exporter.tar
prometheus/prometheus-config-reloader.tar
prometheus/prometheus-operator.tar
prometheus/prometheus.tar

[root@k8s-master prometheus]# cat load-images.sh
#!/bin/bash

cd /root/prometheus

ls /root/prometheus | grep -v load-images.sh > /tmp/k8s-images.txt

for i in $( cat /tmp/k8s-images.txt )
do
docker load -i $i
done
rm -rf /tmp/k8s-images.txt

[root@k8s-master ~]# chmod a+x load-images.sh
[root@k8s-master ~]# ./load-images.sh

传镜像给别的节点
[root@k8s-master ~]# scp -r prometheus/ load-images.sh root@k8s-node1:/root/
[root@k8s-master ~]# scp -r prometheus/ load-images.sh root@k8s-node2:/root/

别的节点导入镜像
[root@k8s-node1 ~]# ./load-images.sh
[root@k8s-node2 ~]# ./load-images.sh

回到主节点
[root@k8s-master prometheus]# cd /root/kube-prometheus/manifests
[root@k8s-master manifests]# kubectl apply -f ../manifests
有报错的时候,多运行几次,因为需要互相连接,直到最后所有created没有报错为止。
[root@k8s-master manifests]# kubectl apply -f ../manifests

[root@k8s-master manifests]# kubectl top node
NAME CPU(cores) CPU% MEMORY(bytes) MEMORY%
k8s-master 164m 8% 1019Mi 17%
k8s-node1 104m 10% 859Mi 49%
k8s-node2 109m 10% 858Mi 45%

[root@k8s-master manifests]# kubectl top pod
NAME CPU(cores) MEMORY(bytes)
my-nginx-7b55868ff4-xldcg 0m 1Mi

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

Prometheus部署
Prometheus部署
prometheus 的 WEB 界面上提供了基本的查询 K8S 集群中每个 POD 的 CPU 使用情况,查询条件如下:
sum by (pod_name)( rate(container_cpu_usage_seconds_total{image!="", pod_name!=""}[1m] ) )
Prometheus部署

下面可以运行后查看图片
Prometheus部署
访问 grafana
grafana 的端口号是 30100,浏览器访问http://MasterIP:30100用户名密码默认 admin/admin
Prometheus部署

Prometheus部署

Prometheus部署

Prometheus部署

Prometheus部署

Prometheus部署

Prometheus部署

这里的监控项都能监控

Prometheus部署

Prometheus部署

上一篇:Ironic 裸金属(Bare Metal)管理


下一篇:Bare HTTP不完全是RESTful