环境说明:
主机名 | 操作系统版本 | ip | docker version | kubelet version | helm version | 配置 | 备注 |
---|---|---|---|---|---|---|---|
master | Centos 7.6.1810 | 172.27.9.131 | Docker 18.09.6 | V1.14.2 | v2.14.3 | 2C2G | master主机 |
node01 | Centos 7.6.1810 | 172.27.9.135 | Docker 18.09.6 | V1.14.2 | v2.14.3 | 2C2G | node节点 |
node02 | Centos 7.6.1810 | 172.27.9.136 | Docker 18.09.6 | V1.14.2 | v2.14.3 | 2C2G | node节点 |
Prometheus
是一个开源系统监控和警报工具包,最初是在soundcloud构建的。自2012年成立以来,许多公司和组织都采用了Prometheus,该项目拥有一个非常活跃的开发人员和用户社区。它现在是一个独立的开源项目,独立于任何公司进行维护,于2016年加入了云原生计算基金会,成为继kubernetes之后的第二个托管项目。
特点:
在微服务架构里,其对多维数据收集和查询有很好的的支持。
Prometheus从jobs获取度量数据,也直接或通过推送网关获取临时jobs的度量数据。它在本地存储所有被获取的样本,并在这些数据运行规则,对现有数据进行聚合和记录新的时间序列,或生成警报。通过Grafana或其他API消费者,可以可视化的查看收集到的数据。
Prometheus Operator是CoreOS开发的基于Prometheus的Kubernetes监控方案
Prometheus Operator:整合Kubernetes和Prometheus的最佳方法
。
Prometheus Operator 功能更特点:
工作流程:
[root@master ~]# git clone https://github.com/coreos/kube-prometheus.git
下载镜像:
docker pull registry.cn-hangzhou.aliyuncs.com/loong576/configmap-reload:v0.0.1
docker pull registry.cn-hangzhou.aliyuncs.com/loong576/alertmanager:v0.18.0
docker pull registry.cn-hangzhou.aliyuncs.com/loong576/kube-state-metrics:v1.8.0
docker pull registry.cn-hangzhou.aliyuncs.com/loong576/kube-rbac-proxy:v0.4.1
docker pull registry.cn-hangzhou.aliyuncs.com/loong576/node-exporter:v0.18.1
docker pull registry.cn-hangzhou.aliyuncs.com/loong576/k8s-prometheus-adapter-amd64:v0.5.0
docker pull registry.cn-hangzhou.aliyuncs.com/loong576/prometheus-config-reloader:v0.33.0
docker pull registry.cn-hangzhou.aliyuncs.com/loong576/prometheus:v2.11.0
docker pull registry.cn-hangzhou.aliyuncs.com/loong576/prometheus-operator:v0.33.0
docker pull registry.cn-hangzhou.aliyuncs.com/loong576/grafana:6.4.3
打tag:
docker tag registry.cn-hangzhou.aliyuncs.com/loong576/configmap-reload:v0.0.1 quay.io/coreos/configmap-reload:v0.0.1
docker tag registry.cn-hangzhou.aliyuncs.com/loong576/alertmanager:v0.18.0 quay.io/prometheus/alertmanager:v0.18.0
docker tag registry.cn-hangzhou.aliyuncs.com/loong576/kube-state-metrics:v1.8.0 quay.io/coreos/kube-state-metrics:v1.8.0
docker tag registry.cn-hangzhou.aliyuncs.com/loong576/kube-rbac-proxy:v0.4.1 quay.io/coreos/kube-rbac-proxy:v0.4.1
docker tag registry.cn-hangzhou.aliyuncs.com/loong576/node-exporter:v0.18.1 quay.io/prometheus/node-exporter:v0.18.1
docker tag registry.cn-hangzhou.aliyuncs.com/loong576/k8s-prometheus-adapter-amd64:v0.5.0 quay.io/coreos/k8s-prometheus-adapter-amd64:v0.5.0
docker tag registry.cn-hangzhou.aliyuncs.com/loong576/prometheus-config-reloader:v0.33.0 quay.io/coreos/prometheus-config-reloader:v0.33.0
docker tag registry.cn-hangzhou.aliyuncs.com/loong576/prometheus:v2.11.0 quay.io/prometheus/prometheus:v2.11.0
docker tag registry.cn-hangzhou.aliyuncs.com/loong576/prometheus-operator:v0.33.0 quay.io/coreos/prometheus-operator:v0.33.0
docker tag registry.cn-hangzhou.aliyuncs.com/loong576/grafana:6.4.3 grafana/grafana:6.4.3
删除镜像:
docker rmi -f registry.cn-hangzhou.aliyuncs.com/loong576/configmap-reload:v0.0.1
docker rmi -f registry.cn-hangzhou.aliyuncs.com/loong576/alertmanager:v0.18.0
docker rmi -f registry.cn-hangzhou.aliyuncs.com/loong576/kube-state-metrics:v1.8.0
docker rmi -f registry.cn-hangzhou.aliyuncs.com/loong576/kube-rbac-proxy:v0.4.1
docker rmi -f registry.cn-hangzhou.aliyuncs.com/loong576/node-exporter:v0.18.1
docker rmi -f registry.cn-hangzhou.aliyuncs.com/loong576/k8s-prometheus-adapter-amd64:v0.5.0
docker rmi -f registry.cn-hangzhou.aliyuncs.com/loong576/prometheus-config-reloader:v0.33.0
docker rmi -f registry.cn-hangzhou.aliyuncs.com/loong576/prometheus:v2.11.0
docker rmi -f registry.cn-hangzhou.aliyuncs.com/loong576/prometheus-operator:v0.33.0
docker rmi -f registry.cn-hangzhou.aliyuncs.com/loong576/grafana:6.4.3
以上三个步骤所有node节点都执行
[root@master kube-prometheus]# kubectl create -f manifests/setup
[root@master kube-prometheus]# kubectl create -f manifests/
[root@master kube-prometheus]# kubectl get all -n monitoring
[root@master kube-prometheus]# kubectl get prometheus --all-namespaces -o wide
所有资源都在monitoring命名空间中。
[root@master kube-prometheus]# kubectl edit -n monitoring service prometheus-k8s
service/prometheus-k8s edited
[root@master kube-prometheus]# kubectl edit -n monitoring service grafana
service/grafana edited
[root@master kube-prometheus]# kubectl edit -n monitoring service alertmanager-main
service/alertmanager-main edited
分别修改service prometheus-k8s、grafana和alertmanager-main,service类型为NodePort,端口分别为30021、30022、30023
http://172.27.9.131:30021
http://172.27.9.131:30023
http://172.27.9.131:30022 用户名密码都为admin
内置模板查看:
集群资源查看:
kubelet查看:
StatefulSets查看:
Pod查看:
API查看:
namespace查看:
查看各节点资源使用:
Prometheus查看:
其他模板:
自带的模板很丰富,不过也可以下载其他模板,比如 ‘1 Node Exporter for Prometheus 监控展示看板 update!’ :https://grafana.com/api/dashboards/8919/revisions/10/download
[root@master kube-prometheus]# kubectl delete --ignore-not-found=true -f manifests/ -f manifests/setup