以下是在Ubuntu上配置Kubernetes監控的步驟:
- 安裝Prometheus:使用Helm安裝Prometheus Operator,它會自動部署Prometheus Server等組件。命令為:
curl https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash
,helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
,helm repo update
,helm install prometheus prometheus-community/kube-prometheus-stack
。
- 配置Prometheus:Prometheus可通過Kubernetes API自動發現監控目標,也可在其配置文件中手動添加,如添加節點、Pod等監控目標。
- 安裝Exporters:在節點上安裝Node Exporter收集節點指標,在需要監控的其他資源處安裝相應Exporter,如監控MySQL數據庫就安裝MySQL Exporter。
- 部署Grafana(可選):用Helm安裝Grafana,將其數據源配置為Prometheus,以便可視化監控數據。
- 設置告警規則:在Prometheus中配置告警規則,定義指標和閾值,當指標超過閾值時觸發告警。