原始的Grafana数据是以emptyDir
形式存放在pod里面,生命周期与pod相同,出现问题时,容器重启,在Grafana里面设置的数据就全部消失了。
查看 grafana pod[root@k8s-master01 ~]# kubectl get pod -n monitoring NAME READY STATUS RESTARTS AGEalertmanager-main-0 2/2 Running 4 29halertmanager-main-1 2/2 Running 2 29halertmanager-main-2 2/2 Running 4 29hgrafana-668c4878fd-js4cb 1/1 Running 2 29hkube-state-metrics-957fd6c75-r2b9v 3/3 Running 3 29hmy-release-prometheus-mysql-exporter-58ff67f687-22qpk 1/1 Running 0 4h1mnode-exporter-btz5d 2/2 Running 4 29hnode-exporter-k6f96 2/2 Running 0 29hnode-exporter-lphjx 2/2 Running 2 29hprometheus-adapter-66b855f564-22vxf 1/1 Running 1 29hprometheus-k8s-0 3/3 Running 7 24hprometheus-k8s-1 3/3 Running 4 24hprometheus-operator-5b96bb5d85-jdbrf 2/2 Running 2 2
查看 grafana pod yaml文件,grafana的volumes 默认使用 emptyDir: {}[root@k8s-master01 ~]# kubectl get pod grafana-668c4878fd-js4cb -n monitoring -o yaml...... volumeMounts: - mountPath: /var/lib/grafana name: grafana-storage...... volumes: - emptyDir: {} name: grafana-storage - name: grafana-datasources......
可以看出Grafana将dashboard、插件这些数据保存在/var/lib/grafana这个目录下面。做数据持久化的话,就需要对这个目录进行volume挂载声明。
安装NFS服务器(为创建静态PV,做准备)
安装NFS服务端,选择集群的k8s-master01节点(192.168.56.10)[root@k8s-master01 ~]# yum install nfs-utils -y (在所有节点安装nfs-utils,并在node节点测试挂载)[root@k8s-master01 ~]# systemctl enable nfs --now在k8s-master01节点上创建nfs目录[root@k8s-master01 ~]# mkdir -p /data/grafana根据下面的报错信息得知,需要对该目录授权nf