Kubernetes部署Prometheus+Grafana(非存儲持久化方式部署)


1.在master節點處新建一個文件夾,用於保存下載prometheus+granfana的yaml文件

mkdir /root/prometheus
cd /root/prometheus
git clone https://github.com/coreos/kube-prometheus.git
cd /root/prometheus/manifest

1583671265039

2.通過manifest和setup文件中的yaml文件可找到需要的鏡像

#需要的鏡像名稱及連接
prometheus-operator:v0.37.0  quay.io/coreos/prometheus-operator:v0.37.0
alertmanager:v0.20.0         quay.io/prometheus/alertmanager:v0.20.0
grafana:6.6.0                grafana/grafana:6.6.0
kube-state-metrics:v1.9.5    quay.io/coreos/kube-state-metrics:v1.9.5   #v1.9.5有問題,建議用1.9.4版本
kube-rbac-proxy:v0.4.1       quay.io/coreos/kube-rbac-proxy:v0.4.1
node-exporter:v0.18.1        quay.io/prometheus/node-exporter:v0.18.1
k8s-prometheus-adapter-amd64:v0.5.0  quay.io/coreos/k8s-prometheus-adapter-amd64:v0.5.0
prometheus:v2.15.2           quay.io/prometheus/prometheus:v2.15.2
configmap-reload:v0.3.0      jimmidyson/configmap-reload:v0.3.0
prometheus-config-reloader:v0.37.0   quay.io/coreos/prometheus-config-reloader:v0.37.0

溫馨提示:只需要在某一個node節點上把以上的鏡像pull回來,再通過保存打包發送到其它的node節點並導入即可
 kube-state-metrics:v1.9.5有問題,會一直提示Error,用回1.9.4版本沒有問題,有二個方法:
 方法1:可以把kube-state-metrics:v1.9.4下載回來。修改標簽為quay.io/coreos/kube-state-metrics:v1.9.5
 方法2:保留標簽為quay.io/coreos/kube-state-metrics:v1.9.4,去manifest文件里面,修改kube-state-metrics-*.yaml的所有文件的標簽1.9.5為1.9.4

所需要的鏡像從阿里雲pull下載

docker pull registry.cn-hangzhou.aliyuncs.com/yfhub/prometheus-operator:v0.37.0
docker pull registry.cn-hangzhou.aliyuncs.com/yfhub/alertmanager:v0.20.0
docker pull registry.cn-hangzhou.aliyuncs.com/yfhub/grafana:6.6.0
docker pull registry.cn-hangzhou.aliyuncs.com/yfhub/kube-state-metrics:v1.9.4
docker pull registry.cn-hangzhou.aliyuncs.com/yfhub/kube-rbac-proxy:v0.4.1
docker pull registry.cn-hangzhou.aliyuncs.com/yfhub/node-exporter:v0.18.1
docker pull registry.cn-hangzhou.aliyuncs.com/yfhub/k8s-prometheus-adapter-amd64:v0.5.0
docker pull rregistry.cn-hangzhou.aliyuncs.com/yfhub/prometheus:v2.15.2
docker pull registry.cn-hangzhou.aliyuncs.com/yfhub/configmap-reload:v0.3.0
docker pull registry.cn-hangzhou.aliyuncs.com/yfhub/prometheus-config-reloader:v0.37.0

3.把下載回來的鏡像重新打標簽

docker tag registry.cn-hangzhou.aliyuncs.com/yfhub/prometheus-operator:v0.37.0 quay.io/coreos/prometheus-operator:v0.37.0

docker tag registry.cn-hangzhou.aliyuncs.com/yfhub/alertmanager:v0.20.0  quay.io/prometheus/alertmanager:v0.20.0

docker tag registry.cn-hangzhou.aliyuncs.com/yfhub/grafana:6.6.0  grafana/grafana:6.6.0

docker tag registry.cn-hangzhou.aliyuncs.com/yfhub/kube-state-metrics:v1.9.4 quay.io/coreos/kube-state-metrics:v1.9.5

docker tag registry.cn-hangzhou.aliyuncs.com/yfhub/kube-rbac-proxy:v0.4.1 quay.io/coreos/kube-rbac-proxy:v0.4.1

docker tag registry.cn-hangzhou.aliyuncs.com/yfhub/node-exporter:v0.18.1 quay.io/prometheus/node-exporter:v0.18.1

docker tag registry.cn-hangzhou.aliyuncs.com/yfhub/k8s-prometheus-adapter-amd64:v0.5.0   quay.io/coreos/k8s-prometheus-adapter-amd64:v0.5.0

docker tag registry.cn-hangzhou.aliyuncs.com/yfhub/prometheus:v2.15.2 quay.io/prometheus/prometheus:v2.15.2

docker tag registry.cn-hangzhou.aliyuncs.com/yfhub/configmap-reload:v0.3.0 jimmidyson/configmap-reload:v0.3.0

docker tag registry.cn-hangzhou.aliyuncs.com/yfhub/prometheus-config-reloader:v0.37.0 quay.io/coreos/prometheus-config-reloader:v0.37.0

docker tag registry.cn-hangzhou.aliyuncs.com/yfhub/prometheus-config-reloader:v0.37.0  quay.io/coreos/prometheus-config-reloader:v0.37.0

**刪除從阿里雲下載回來的鏡像

docker rmi registry.cn-hangzhou.aliyuncs.com/yfhub/prometheus-operator:v0.37.0
docker rmi registry.cn-hangzhou.aliyuncs.com/yfhub/alertmanager:v0.20.0
docker rmi registry.cn-hangzhou.aliyuncs.com/yfhub/grafana:6.6.0
docker rmi registry.cn-hangzhou.aliyuncs.com/yfhub/kube-state-metrics:v1.9.4
docker rmi registry.cn-hangzhou.aliyuncs.com/yfhub/kube-rbac-proxy:v0.4.1
docker rmi registry.cn-hangzhou.aliyuncs.com/yfhub/node-exporter:v0.18.1
docker rmi registry.cn-hangzhou.aliyuncs.com/yfhub/k8s-prometheus-adapter-amd64:v0.5.0
docker rmi rregistry.cn-hangzhou.aliyuncs.com/yfhub/prometheus:v2.15.2
docker rmi registry.cn-hangzhou.aliyuncs.com/yfhub/configmap-reload:v0.3.0
docker rmi registry.cn-hangzhou.aliyuncs.com/yfhub/prometheus-config-reloader:v0.37.0

4.把修改好標簽的鏡像重新保存為tar文件,方便傳到另外的Node節點

mkdir -p /root/prometheus/pgbase.images
cd /root/prometheus/pgbase.images
docker save -o prometheus-operator-v0.37.0.tar  quay.io/coreos/prometheus-operator:v0.37.0
docker save -o alertmanager-v0.20.0.tar         quay.io/prometheus/alertmanager:v0.20.0
docker save -o grafana-6.6.0.tar                grafana/grafana:6.6.0
docker save -o kube-state-metrics-v1.9.5.tar    quay.io/coreos/kube-state-metrics:v1.9.5
docker save -o kube-rbac-proxy-v0.4.1.tar       quay.io/coreos/kube-rbac-proxy:v0.4.1
docker save -o node-exporter-v0.18.1.tar        quay.io/prometheus/node-exporter:v0.18.1
docker save -o k8s-prometheus-adapter-amd64-v0.5.0.tar  quay.io/coreos/k8s-prometheus-adapter-amd64:v0.5.0
docker save -o prometheus-v2.15.2.tar           quay.io/prometheus/prometheus:v2.15.2
docker save -o configmap-reload-v0.3.0.tar      jimmidyson/configmap-reload:v0.3.0
docker save -o prometheus-config-reloader-v0.37.0.tar   quay.io/coreos/prometheus-config-reloader:v0.37.0

5.把打包好的鏡像文件傳到其它的Node節點

scp -r /root/prometheus/pgbase.images k8s-node02:/root/

6.在其它Node節點導入鏡像

docker load -i alertmanager-v0.20.0.tar && docker load -i kube-rbac-proxy-v0.4.1.tar && docker load -i prometheus-operator-v0.37.0.tar && docker load -i configmap-reload-v0.3.0.tar & docker load -i kube-state-metrics-v1.9.5.tar && docker load -i prometheus-v2.15.2.tar && docker load -i grafana-6.6.0.tar && docker load -i node-exporter-v0.18.1.tar && docker load -i k8s-prometheus-adapter-amd64-v0.5.0.tar && docker load -i prometheus-config-reloader-v0.37.0.tar

7.把node-exporter和kube-rbac-proxy鏡像上傳到master節點並導入

#在打包鏡像的node節點上把node-exporter鏡像傳到master節點
scp -r /root/prometheus/pgbase.images/node-exporter-v0.18.1.tar k8s-master01:/root/
scp -r /root/prometheus/pgbase.images/kube-rbac-proxy-v0.4.1.tar k8s-master01:/root/

#在master節點上導入node-exporter
docker load -i /root/node-exporter-v0.18.1.tar
docker load -i /root/kube-rbac-proxy-v0.4.1.tar

8修改grafana-service.yaml暴露svc端口

apiVersion: v1
kind: Service
metadata:
  labels:
    app: grafana
  name: grafana
  namespace: monitoring
spec:
  type: NodePort       #默認此選項是沒有的,故需要添加NodePort來,讓外網訪問,也可能通過ingress-nginx來暴露
  ports:
  - name: http
    port: 3000
    targetPort: http
  selector:
    app: grafana

9.在master主節點上應用yamly文件

kubectl apply -f /root/prometheus/kube-prometheus/manifests/setup/
kubectl apply -f /root/prometheus/kube-prometheus/manifests/

10.查看pod有沒有都已經運行

1583728778952

11.查看grafana的svc對外的端口(NodePort)

1583728853917

12.使用IP:端口訪問grafana

1583728994469

溫馨提示:grafana的用戶名:admin    密碼為:admin
第一次登錄,會提示你需要修改密碼。

13.配置數據源**

溫馨提示:默認就已經給你配置好了數據源(Data Sources / prometheus),單擊“Test”是否能連接成功

1583729204866

14.Dashboards導入模板

1583729328311

15瀏覽效果

1583729387735


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM