在CentOS上监控Kubernetes(k8s)集群中的容器,可以采用多种监控工具和方法。以下是一些常用的监控工具和解决方案:
# 使用Helm安装Prometheus和Grafana
kubectl apply -f https://raw.githubusercontent.com/coreos/kube-prometheus/master/manifests/grafana/grafana.yaml
kubectl apply -f https://raw.githubusercontent.com/prometheus-community/helm-charts/releases/latest/download/prometheus-chart.tgz
helm install prometheus stable/prometheus --set global.storage.size=10Gi
编辑Prometheus的配置文件(通常位于/prometheus/prometheus.yml
),添加以下配置来抓取Kubernetes的指标:
scrape_configs:
- job_name: 'kubernetes-nodes'
kubernetes_sd_configs:
- role: node
relabel_configs:
- source_labels: [__meta_kubernetes_node_label_app]
action: keep
regex: kube-state-metrics
action: replace
target_label: __address__
replacement: :9090
- source_labels: [__meta_kubernetes_node_annotation_prometheus_io_scrape]
action: keep
regex: "true"
- source_labels: [__meta_kubernetes_node_annotation_prometheus_io_port]
action: replace
target_label: __address__
replacement: :9090
打开Grafana,添加Prometheus作为数据源,创建一个新的Dashboard,并添加各种Kubernetes监控面板。
通过上述步骤和工具,你可以在CentOS上的Kubernetes集群中实现有效的监控和告警,确保系统的稳定运行。