在Prometheus Operator中配置Consul自動發現服務
阿新 • • 發佈:2021-12-15
# 1.在monitoring名稱空間部署consul服務 cat > consul.yaml << EOF apiVersion: apps/v1 kind: Deployment metadata: name: consul namespace: monitoring labels: app: consul spec: selector: matchLabels: app: consul replicas: 1 template: metadata: name: consul labels: app: consul spec: containers: - name: consul image: consul:latest ports: - containerPort: 8500 protocol: TCP imagePullPolicy: IfNotPresent --- apiVersion: v1 kind: Service metadata: name: consul namespace: monitoring labels: app: consul spec: selector: app: consul ports: - name: consul protocol: TCP port: 8500 targetPort: 8500 EOF kubectl apply -f consul.yaml # 2.編寫prometheus-additional並在monitoring名稱空間建立secret資源 cat > prometheus-additional.yaml << EOF - job_name: consul consul_sd_configs: - server: consul.monitoring.svc:8500 EOF kubectl create secret generic additional-configs --from-file=prometheus-additional.yaml -n monitoring # 3.手動修改kube-prometheus/manifests中的prometheus-prometheus.yaml檔案增加additionalScrapeConfigs配置段 vim kube-prometheus/manifests/prometheus-prometheus.yaml additionalScrapeConfigs: name: additional-configs key: prometheus-additional.yaml # 並重新應用prometheus-prometheus.yaml檔案 kubectl apply -f kube-prometheus/manifests/prometheus-prometheus.yaml