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

posted on 2020-03-10 17:34  杨枫哥  阅读(1998)  评论(7编辑  收藏  举报