我在裸机上配置普罗米修斯时遇到了同样的问题,这就是我解决它的方法。
您可以使用local-storage
PV 和 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 已绑定到该节点