1、Prometheus持久化

  • 创建pv
apiVersion: v1
kind: PersistentVolume
metadata:
  annotations:
    pv.kubernetes.io/bound-by-controller: "yes"
  finalizers:
  - kubernetes.io/pv-protection
  name: prom-pv
spec:
  accessModes:
  - ReadWriteOnce
  capacity:
    storage: 5Gi
  local:
    path: /data/prom
  nodeAffinity:
    required:
      nodeSelectorTerms:
      - matchExpressions:
        - key: prom-node
          operator: In
          values:
          - "true"
  persistentVolumeReclaimPolicy: Retain
  storageClassName: prom-data
  volumeMode: Filesystem
  • 修改prometheus配置文件
  • 在Path/to/kube-prometheus/manifests/prometheus-prometheus.yaml中做如下修改:
apiVersion: monitoring.coreos.com/v1
kind: Prometheus
metadata:
  labels:
    prometheus: k8s
  name: k8s
  namespace: monitoring
spec:
  alerting:
    alertmanagers:
    - name: alertmanager-main
      namespace: monitoring
      port: web
#-----storage-----
  storage: #这部分为持久化配置
    volumeClaimTemplate:
      spec:
        storageClassName: prom-data		#对应pvc的storageclassname
        accessModes: ["ReadWriteOnce"]
        resources:
          requests:
            storage: 100Gi

如果已经创建啦prometheus
则可以在线增加上述注释以下区域
kubectl edit prometheus k8s -n monitoring

注意事项:

  • 如果需要修改prometheus的数量,也是在此修改,在prometheus的statefulset修改无效

grafana的持久化

  • 创建pv
apiVersion: v1
kind: PersistentVolume
metadata:
  annotations:
    pv.kubernetes.io/bound-by-controller: "yes"
  finalizers:
  - kubernetes.io/pv-protection
  name: grafana-pv
spec:
  accessModes:
  - ReadWriteOnce
  capacity:
    storage: 5Gi
  local:
    path: /data/grafana
  nodeAffinity:
    required:
      nodeSelectorTerms:
      - matchExpressions:
        - key: grafana-node
          operator: In
          values:
          - "true"
  persistentVolumeReclaimPolicy: Retain
  storageClassName: grafana-data
  volumeMode: Filesystem
  • 修改配置文件
# 先创建pvc
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
    name: grafana-pvc
    namespace: monitoring
spec:
  accessModes:
  - ReadWriteOnce
  resources:
    requests:
      storage:  5Gi
  storageClassName:  grafana-data

 
# 然后在grafana-deployment.yaml将emptydir存储方式改为pvc方式:

      #- emptyDir: {}
      #  name: grafana-storage
      - name: grafana-storage
        persistentVolumeClaim:
          claimName: grafana-data		#注意此处为pvc的名字
      - name: grafana-datasources
        secret:
          secretName: grafana-datasources
      - configMap:
          name: grafana-dashboards
        name: grafana-dashboards
      - configMap:
          name: grafana-dashboard-apiserver
        name: grafana-dashboard-apiserver
      - configMap:
          name: grafana-dashboard-controller-manager

3、Prometheus的存储时长配置

kubectl edit prometheus k8s -n monitoring
在这里插入图片描述
我这里设置两小时,天的单位为:d

在这里插入图片描述
在这里插入图片描述

Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐