kube-prometheus 集成部署 blackbox-exporter

编写 blackbox.yaml

配置文件用 configmap 挂载。

kubectl apply -f cm-blackbox-external-config.yaml

apiVersion: v1
kind: ConfigMap
metadata:
  name: blackbox-external-config
  namespace: monitoring
data:
  config.yml: |-
    "modules":
      "http_2xx":
        "prober": "http"
        "timeout": "5s"
        "http":
          "valid_http_versions": ["HTTP/1.1", "HTTP/2"]
          "valid_status_codes": []
          "method": "GET"
          "preferred_ip_protocol": "ip4"
          "fail_if_ssl": flase
          "fail_if_not_ssl": flase

      "http_2xx_3xx":
        "prober": "http"
        "timeout": "5s"
        "http":
          "valid_http_versions": ["HTTP/1.1", "HTTP/2"]
          "valid_status_codes": [ 200, 201, 202, 203, 204, 205, 206, 207, 208, 226, 300, 301, 302, 303, 304, 305, 306, 307, 308 ]
          "method": "GET"
          "preferred_ip_protocol": "ip4"
          "fail_if_ssl": flase
          "fail_if_not_ssl": flase

      "http_post_2xx_3xx":
        "prober": "http"
        "timeout": "5s"
        "http":
          "valid_http_versions": ["HTTP/1.1", "HTTP/2"]
          "valid_status_codes": [ 200, 201, 202, 203, 204, 205, 206, 207, 208, 226, 300, 301, 302, 303, 304, 305, 306, 307, 308 ]
          "method": "POST"
          "preferred_ip_protocol": "ip4"
          "fail_if_ssl": flase
          "fail_if_not_ssl": flase

      "tcp_connect":
        "prober": "tcp"
        "timeout": "5s"
        "tcp":
          "preferred_ip_protocol": "ip4"

      "icmp":
        "prober": "icmp"
        "timeout": "5s"
        "icmp":
          "preferred_ip_protocol": "ip4"
部署 blackbox_exporter:0.24.0

kubectl apply -f blackbox-external.yaml,包含 deploy、svc、ingress。

# blackbox-exporter-deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: blackbox-external
  namespace: monitoring
spec:
  replicas: 1
  selector:
    matchLabels:
      app: blackbox-external
  template:
    metadata:
      labels:
        app: blackbox-external
    spec:
      containers:
      - name: blackbox-exporter
        image: bitnami/blackbox-exporter:0.24.0
        ports:
        - containerPort: 9115
        volumeMounts:
        - name: config-volume
          mountPath: /etc/blackbox_exporter/
  volumes:
  - name: config-volume
    configMap:
      name: blackbox-external-config

---
# blackbox-exporter-service.yaml
apiVersion: v1
kind: Service
metadata:
  name: blackbox-external
  namespace: monitoring
spec:
  selector:
    app: blackbox-external
  ports:
  - name: http
    protocol: TCP
    port: 9115
    targetPort: 9115
    nodePort: 30115
  type: NodePort
  
---
# blackbox-exporter-ingress.yaml  没有 ingress 可以省略
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: blackbox-external-ingress
  namespace: monitoring
spec:
  rules:
  - host: your.domain.com # 填写你的域名,要配置相应的 DNS 解析
    http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: blackbox-external
            port:
              number: 9115
添加 scrape_configs

cat prometheus-additional.yaml,另外添加的 scrape_target 都写在这个文件,不熟的同学可以先看这里

......
- job_name: "DNS"
  scrape_interval: 30s
  metrics_path: /probe
  params:
    module: [tcp_connect]
  static_configs:
  - targets: ['10.1.11.78:53']
    #labels:
    #  address: '10.1.11.78:53'   #添加label,便于告警区分
  - targets: ['10.1.11.79:53']
    #labels:
    #  address: '10.1.11.79:53'
  relabel_configs:
  - source_labels: [__address__]
    target_label: __param_target
  - source_labels: [__param_target]
    target_label: instance
  - target_label: __address__           # blackbox 是 service 的名字
    replacement: blackbox-external:9115 # prometheus 和 blackbox 不在同namespace请填写:blackbox-external.kube-system.svc.cluster.local:9115
......

 更新另外添加的 scrape_configs

#先删除
kubectl delete -n monitoring secret additional-configs 

#再创建
kubectl create -n monitoring secret additional-configs --from-file=prometheus-additional.yaml

等一会查看 prometheus web

查看 blackbox web

  • 4
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值