有什么辦法可以根據 Prometheus 發出的警報運行 pod?我們有一個場景,我們需要根據磁盤壓力閾值執行一個 pod。我能夠創建警報,但我需要執行一個 pod。我怎樣才能做到這一點?
groups:
- name: node_memory_MemAvailable_percent
rules:
- alert: node_memory_MemAvailable_percent_alert
annotations:
description: Memory on node {{ $labels.instance }} currently at {{ $value }}%
is under pressure
summary: Memory usage is under pressure, system may become unstable.
expr: |
100 - ((node_memory_MemAvailable_bytes{job="node-exporter"} * 100) / node_memory_MemTotal_bytes{job="node-exporter"}) > 80
for: 2m
labels:
severity: warning
uj5u.com熱心網友回復:
我認為 Alertmanager 可以幫助您,使用webhook接收器(檔案)。
這樣,當警報被觸發時,Prometheus 將其發送到 Alertmanager,然后 Alertmanager 對自定義 webhook 執行 POST。
當然,您需要實作一個服務來處理警報并運行您的操作。
uj5u.com熱心網友回復:
通常,您的問題顯示磁盤壓力,在代碼中我可以看到可用記憶體量。如果您想根據記憶體上下擴展副本,您可以實作Horizo??ntal Pod Autoscaler:
Horizo??ntal Pod Autoscaler 實作為一個控制回圈,其周期由控制器管理器的
--horizontal-pod-autoscaler-sync-period標志控制 (默認值為 15 秒)。在每個時間段內,控制器管理器根據每個 Horizo??ntalPodAutoscaler 定義中指定的指標查詢資源利用率。控制器管理器從資源指標 API(對于每個 Pod 資源指標)或自定義指標 API(對于所有其他指標)獲取指標。
您可以根據記憶體利用率創建自己的 HPA 。這是示例:
apiVersion: autoscaling/v2beta2
kind: HorizontalPodAutoscaler
metadata:
name: php-memory-scale
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: php-apache
minReplicas: 1
maxReplicas: 10
metrics:
- type: Resource
resource:
name: memory
target:
type: Utilization
averageValue: 10Mi
您還可以使用來自 Prometheus 的自定義指標創建自定義Kubernetes HPA:
自動縮放是一種根據資源使用情況自動擴大或縮小作業負載的方法。K8s水平 Pod 自動縮放器 :
- 被實作為一個控制回圈,它 通過metrics.k8s.io API定期查詢Resource Metrics API 以獲得 核心指標,例如CPU/記憶體和用于應用程式特定指標的Custom Metrics API (external.metrics.k8s.io 或custom.metrics.k8s.io 。 metrics.k8s.io API。它們由指標解決方案供應商提供的“配接器”API服務器提供。有一些 已知的解決方案,但這些實作都不是Kubernetes的正式組成部分)
- 根據觀察到的指標自動擴展部署或副本集中的 pod 數量。
在接下來的內容中,我們將重點關注自定義指標,因為自定義指標 API 使Prometheus等監控系統 能夠將特定于應用程式的指標公開給 HPA 控制器。
另一種解決方案可能是使用KEDA。看看這個指南。這是用于監控來自 nginx 的 500 個錯誤的示例 yaml:
apiVersion: keda.sh/v1alpha1
kind: ScaledObject
metadata:
name: nginx-scale
namespace: keda-hpa
spec:
scaleTargetRef:
kind: Deployment
name: nginx-server
minReplicaCount: 1
maxReplicaCount: 5
cooldownPeriod: 30
pollingInterval: 1
triggers:
- type: prometheus
metadata:
serverAddress: https://prometheus_server/prometheus
metricName: nginx_connections_waiting_keda
query: |
sum(nginx_connections_waiting{job="nginx"})
threshold: "500"
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/359009.html
標籤:Kubernetes 普罗米修斯 prometheus-alertmanager
上一篇:Kubernetes控制平面通信
