1.MetricServer:是 kubernetes 集群资源使用情况的聚合器,收集数据给 kubernetes 集群内使用,如 kubectl,scheduler 等。
2.PrometheusOperator:是一个系统监测和警报工具箱,用来存储监控数据。
3.NodeExporter:用于各 node 的关键度量指标状态数据。
4.KubeStateMetrics:收集 kubernetes集群内资源对象数据,指定告警规则。
5.Prometheus:采用 pull 方式收集 apiserver,sheduler,controller-manager,kubelet 组件数据,通过http协议传输。
6.Grafana:是可视化数据统计和监控平台。
mkdir /kubernetes/prometheus ; cd /kubernetes/prometheus
git clone https://github.com/coreos/kube-prometheus.git
cd kube-prometheus/manifests/ 进入yaml文件模板目录
apiVersion: v1
kind: Service
metadata:
labels:
app: grafana
name: grafana
namespace: monitoring
spec:
type: NodePort #添加暴露端口
ports:
- name: http
port: 3000
targetPort: http
nodePort: 30100 #暴露端口为 30100
selector:
app: grafana
~
apiVersion: v1
kind: Service
metadata:
labels:
prometheus: k8s
name: prometheus-k8s
namespace: monitoring
spec:
type: NodePort
ports:
- name: web
port: 9090
targetPort: web
nodePort: 30200
selector:
app: prometheus
prometheus: k8s
sessionAffinity: ClientIP
~
apiVersion: v1
kind: Service
metadata:
labels:
alertmanager: main
name: alertmanager-main
namespace: monitoring
spec:
type: NodePort
ports:
- name: web
port: 9093
targetPort: web
nodePort: 30300
selector:
alertmanager: main
app: alertmanager
sessionAffinity: ClientIP
~
下载 prometheus 所需要的镜像,这些所有需要下载的镜像,皆为 Kube-prometheus 目录下的 yaml 文件中已经定义好的镜像文件,提前下载好打包而已
docker pull registry.cn-hangzhou.aliyuncs.com/prometheus/addon-resizer:1.7
docker pull quay.io/prometheus/alertmanager:v0.20.0
docker pull registry.cn-hangzhou.aliyuncs.com/lz_prometheus/configmap-reload:v0.0.1
docker pull grafana/grafana:6.7.4
docker pull directxman12/k8s-prometheus-adapter:v0.7.0
docker pull registry.cn-hangzhou.aliyuncs.com/lz_prometheus/kube-rbac-proxy:v0.4.1
docker pull quay.io/coreos/kube-state-metrics:v1.9.5
docker pull quay.io/prometheus/node-exporter:v0.18.1
docker pull quay.io/coreos/prometheus-operator:v0.40.0
docker pull quay.io/prometheus/prometheus:v2.17.2
封装成 tar 包
docker save -o kube-rbac-proxy.tar registry.cn-hangzhou.aliyuncs.com/lz_prometheus/kube-rbac-proxy:v0.4.1
docker save -o prometheus-operator.tar quay.io/coreos/prometheus-operator:v0.40.0
docker save -o prometheus-prometheus.tar quay.io/prometheus/prometheus:v2.17.2
docker save -o kube-state-metrics.tar quay.io/coreos/kube-state-metrics:v1.9.5
docker save -o prometheus-alertmanager.tar quay.io/prometheus/alertmanager:v0.20.0
docker save -o prometheus-adapter.tar directxman12/k8s-prometheus-adapter:v0.7.0
docker save -o grafana.tar grafana/grafana:6.7.4
docker save -o prometheus-addon-resizer.tar registry.cn-hangzhou.aliyuncs.com/prometheus/addon-resizer:1.7
docker save -o prometheus-configmap-reload.tar registry.cn-hangzhou.aliyuncs.com/lz_prometheus/configmap-reload:v0.0.1
docker save -o node-exporter.tar quay.io/prometheus/node-exporter:v0.18.1
[root@harbor ~]# tar -zcvf /usr/src/k8s-prometheus.tar.gz ./*.tar
./grafana.tar
./kube-rbac-proxy.tar
./kube-state-metrics.tar
./node-exporter.tar
./prometheus-adapter.tar
./prometheus-addon-resizer.tar
./prometheus-alertmanager.tar
./prometheus-configmap-reload.tar
./prometheus-operator.tar
./prometheus-prometheus.tar
导入到 master节点 与 各个node节点
docker load --input kube-rbac-proxy.tar
docker load --input kube-state-metrics.tar
docker load --input node-exporter.tar
docker load --input prometheus-adapter.tar
docker load --input prometheus-addon-resizer.tar
docker load --input prometheus-alertmanager.tar
docker load --input prometheus-configmap-reload.tar
docker load --input prometheus-operator.tar
docker load --input prometheus-prometheus.tar
docker load --input grafana.tar
kubectl create -f manifests/setup 执行创建环境的文件
kubectl create -f manifests/ 执行 prometheus-pod 的安装
kubectl get pod -n monitoring 查看结果在 monitoring 名称空间下查看,出现以下结果代表成功
将 prometheus 配置全部删除:
kubectl delete --ignore-not-found=true -f manifests/ -f manifests/setup
kubectl get svc -n monitoring 查看 NodePort 暴露端口
通过 prometheus-k8s数据采集端 进行首次登录 http://192.168.168.11:30200
例如,输入以下表达式以绘制在自抓取的Prometheus中创建的块的每秒速率
rate(prometheus_tsdb_head_chunks_created_total[1m])
http://192.168.168.11:30100/login
登录之后需要输入默认的用户名密码,都是 admin;然后会提示让你更新密码,此时输入新密码即可:“123.com”
在默认的监控项里,已经对基础的资源监控都设置好了,因为直接采用的 github上的prometheus