无法设置 Prometheus 监控 EBS 上的 Kubernetes 指标持久存储

Unable to setup Promethues monitored Kubernetes metrics persistent storage on EBS

我在 AWS 上使用 kops. I also got prometheus and grafana set up using kube-prometheus 获得了一个 kubernetes 集群 运行。

我想做的是将 prometheus 收集的指标存储在 EBS 上。我的持久卷声明 yaml 是:

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: prometheus-data
  namespace: monitoring

spec:
  accessModes:
  - ReadWriteOnce
  resources:
    requests:
      storage: 10Gi

而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
  baseImage: quay.io/prometheus/prometheus
  nodeSelector:
    beta.kubernetes.io/os: linux
  replicas: 2
  resources:
    requests:
      memory: 400Mi
    volumeMounts:
     - name: prometheus-data
       mountPath: "/data"
  ruleSelector:
    matchLabels:
      prometheus: k8s
      role: alert-rules
  volumes:
  - name: prometheus-data
    persistentVolumeClaim:
     claimName: prometheus-data
  serviceAccountName: prometheus-k8s
  serviceMonitorNamespaceSelector: {}
  serviceMonitorSelector: {}
  version: v2.4.3

正在创建 10Gi EBS 卷,但它的状态仍然可用。我还尝试删除 prometheus pods 希望数据能够保留。不幸的是,情况并非如此。

我能够使用持久存储设置 kube-prometheus。请检查以下 json 个文件:

普罗米修斯-deploy.json

{
"apiVersion": "monitoring.coreos.com/v1",
"kind": "Prometheus",
"metadata": {
    "labels": {
        "prometheus": "k8s"
    },
    "name": "k8s-prom",
    "namespace": "monitoring"
},
"spec": {
    "alerting": {
        "alertmanagers": [
            {
                "name": "alertmanager-main",
                "namespace": "monitoring",
                "port": "web"
            }
        ]
    },
    "baseImage": "quay.io/prometheus/prometheus",
    "replicas": 1,
    "resources": {
        "requests": {
            "memory": "400Mi"
        }
    },
    "ruleSelector": {
        "matchLabels": {
            "prometheus": "k8s",
            "role": "alert-rules"
        }
    },
    "securityContext": {
        "fsGroup": 0,
        "runAsNonRoot": false,
        "runAsUser": 0
    },
    "serviceAccountName": "prometheus",
    "serviceMonitorSelector": {
        "matchExpressions": [
            {
                "key": "k8s-app",
                "operator": "Exists"
            }
        ]
    },
    "storage": {
        "class": "",
        "resources": {},
        "selector": {},
        "volumeClaimTemplate": {
            "spec": {
                "resources": {
                    "requests": {
                        "storage": "10Gi"
                    }
                },
                "selector": {
                    "matchLabels": {
                        "app": "k8s-vol"
                    }
                },
                "storageClassName": "no-provision"
            }
        }
    },
    "version": "v2.2.1"
} }

普罗米修斯-pv.json

{
"apiVersion": "v1",
"kind": "PersistentVolume",
"metadata": {
    "labels": {
        "app": "k8s-vol"
    },
    "name": "prometheus-vol",
    "namespace": "monitoring"
},
"spec": {
    "storageClassName": "no-provision",
    "accessModes": [
        "ReadWriteOnce"
    ],
    "capacity": {
        "storage": "10Gi"
    },
    "hostPath": {
        "path": "/data"
    },
    "persistentVolumeReclaimPolicy": "Retain"
},
"status": {
    "phase": "Bound"
} }

希望对您有所帮助。