1

Kubernetes 版本:1.10

我们在 Kubernetes 集群上运行 Prometheus(在裸机上运行)。Kubernetes 仅使用一个 POD 运行。

ISSUE - 如果 POD 重新启动,Prometheus 指标不会保留。我们还尝试将持久性卷配置为local。现在,如果该 pod 被重新调度到集群的任何其他节点,那么它将丢失所有先前保存在前一个节点上的数据。我们还尝试将 Prometheus 远程存储配置为读写,但是由于速度很慢,所以没有成功。是否有任何其他选项可以将数据持久保存在裸机上的 Kubernetes 上?

4

1 回答 1

0

我在裸机上配置普罗米修斯时遇到了同样的问题,这就是我解决它的方法。

您可以使用local-storagePV 和 PVC 的存储类,将您的 PVC 绑定到您的节点。因此,每当节点重启 pod 将被安排在 PVC 所在的同一节点上。我正在分享我的 json 文件:

普罗米修斯-pv.json

{
  "kind": "PersistentVolume",
  "apiVersion": "v1",
  "metadata": {
    "name": "prometheus-vol",
    "namespace": "monitoring"
    "labels": {
      "type": "local",
      "app": "harmony-vol"
    }
  },
  "spec": {
    "capacity": {
      "storage": "10Gi"
    },
    "accessModes": [
      "ReadWriteOnce"
    ],
    "storageClassName": "local-storage",
    "local": {
      "path": "/data"
    },
    "claimRef": {
      "namespace": "default",
      "name": "data-prafull-0"
    },
    "nodeAffinity": {
      "required": {
        "nodeSelectorTerms": [
          {
            "matchExpressions": [
              {
                "key": "kubernetes.io/hostname",
                "operator": "In",
                "values": [
                  "<node_name>"
                ]
              }
            ]
          }
        ]
      }
    }
  }
}

普罗米修斯.json

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

应用此操作后,您的 pod 将不会重新调度到另一个节点,因为 PV、PVC 已绑定到该节点

于 2018-12-04T09:18:38.157 回答