1

我使用kops在 AWS 上运行了一个 kubernetes 集群。我还使用kube-prometheus设置了 prometheus 和 grafana 。

我想要做的是将普罗米修斯收集的指标存储在 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 pod,希望能保留数据。不幸的是,情况并非如此。

4

1 回答 1

1

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

Promethues-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"
} }

希望能帮助到你。

于 2018-10-22T07:48:25.437 回答