乐闻世界logo
搜索文章和话题

How to deploy and use Prometheus in Kubernetes environments?

2月21日 15:40

Deployment and usage of Prometheus in Kubernetes environments:

Deployment Methods:

  1. Helm Chart Deployment (Recommended):
bash
helm install prometheus prometheus-community/kube-prometheus-stack
  1. Operator Deployment:
  • Use Prometheus Operator for simplified management
  • Provides CRDs: Prometheus, Alertmanager, ServiceMonitor, etc.

Key Components:

  • Prometheus: Main monitoring service
  • Node Exporter: Node metrics collection
  • Kubelet Metrics: Container and Pod metrics
  • cAdvisor: Container resource usage
  • Kube-State-Metrics: Kubernetes object status

ServiceMonitor Configuration:

yaml
apiVersion: monitoring.coreos.com/v1 kind: ServiceMonitor metadata: name: my-app spec: selector: matchLabels: app: my-app endpoints: - port: metrics interval: 30s

Common Metrics:

  • Container resources: container_cpu_usage_seconds_total
  • Pod status: kube_pod_status_phase
  • Node resources: node_memory_MemAvailable_bytes
  • Network traffic: container_network_receive_bytes_total

Auto-Discovery Configuration:

yaml
scrape_configs: - job_name: 'kubernetes-pods' kubernetes_sd_configs: - role: pod relabel_configs: - source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_scrape] action: keep regex: true

Best Practices:

  • Use namespaces to isolate monitoring data
  • Configure resource limits to avoid impacting business
  • Use PersistentVolume for data persistence
  • Regularly backup configuration and data
  • Create dashboards with Grafana
标签:Prometheus