使用Prometheus原生yaml配置blackbox-exporter的教程遍地都是,使用serviceMonitor进行配置的却比较少,为了让大家少踩坑,现将完整配置贴下,一贴搞定!
首先配置configmap
apiVersion: v1
kind: ConfigMap
metadata:
name: blackbox-exporter
namespace: product-coc-monitor
labels:
app: blackbox-exporter
data:
blackbox.yml: |-
modules:
http_2xx:
prober: http
timeout: 2s
http:
valid_http_versions: ["HTTP/1.1", "HTTP/2"]
valid_status_codes: [200,301,302]
method: GET
preferred_ip_protocol: "ip4"
tcp_connect:
prober: tcp
timeout: 2s
配置ingress
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: blackbox-exporter
namespace: kube-system
status:
loadBalancer:
ingress:
- ip: 自动生成的ip
spec:
rules:
- host: blackbox.od.com
http:
paths:
- path: /
pathType: ImplementationSpecific
backend:
serviceName: blackbox-exporter
servicePort: blackbox-port
配置deployment
apiVersion: apps/v1
kind: Deployment
metadata:
name: blackbox-exporter
namespace: product-coc-monitor
labels:
app: blackbox-exporter
spec:
replicas: 1
selector:
matchLabels:
app: blackbox-exporter
template:
metadata:
creationTimestamp: null
labels:
app: blackbox-exporter
annotations:
kubectl.kubernetes.io/restartedAt: '2022-06-28T04:26:04Z'
spec:
volumes:
- name: config
configMap:
name: blackbox-exporter
defaultMode: 420
containers:
- name: blackbox-exporter
image: harbor.ceclouddyn.com/intranet/blackbox-exporter:v0.21.1
args:
- '--config.file=/etc/blackbox_exporter/blackbox.yml'
- '--log.level=info'
- '--web.listen-address=:9115'
ports:
- name: blackbox-port
containerPort: 9115
protocol: TCP
resources:
limits:
cpu: 200m
memory: 256Mi
requests:
cpu: 100m
memory: 50Mi
volumeMounts:
- name: config
mountPath: /etc/blackbox_exporter
readinessProbe:
tcpSocket:
port: 9115
initialDelaySeconds: 5
timeoutSeconds: 5
periodSeconds: 10
successThreshold: 1
failureThreshold: 3
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
imagePullPolicy: IfNotPresent
restartPolicy: Always
terminationGracePeriodSeconds: 30
dnsPolicy: ClusterFirst
securityContext: {}
schedulerName: default-scheduler
strategy:
type: RollingUpdate
rollingUpdate:
maxUnavailable: 25%
maxSurge: 25%
revisionHistoryLimit: 10
progressDeadlineSeconds: 600
配置service
apiVersion: v1
kind: Service
metadata:
name: blackbox-exporter
namespace: product-coc-monitor
labels:
app: org0-orderer1
spec:
ports:
- name: blackbox-port
protocol: TCP
port: 9115
targetPort: 9115
selector:
app: blackbox-exporter
clusterIP: 自动生成的IP
type: ClusterIP
sessionAffinity: None
配置serviceMoniter
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
name: prometheus-blackbox-exporter
namespace: product-coc-monitor
spec:
endpoints:
- params:
module:
- http_2xx
target:
- web:3000
path: /probe
port: blackbox-port
- params:
module:
- icmp
target:
- 10.253.16.17
path: /probe
port: blackbox-port
namespaceSelector:
matchNames:
- product-coc-monitor
selector:
matchLabels:
app: org0-orderer1
按照以上配置即可在Prometheus的页面看到blackbox-exporter的配置啦