交付blackbox-exporter

blackbox-exporter官方dockerhub地址

blackbox-exporter官方github地址

准备镜像

1
2
3
4
5
[root@ops-200 ~]# docker pull prom/blackbox-exporter:v0.16.0
[root@ops-200 ~]# docker images|grep blackbox-exporter
prom/blackbox-exporter v0.16.0 5e5949f1bda7 5 months ago 19.7MB
[root@ops-200 ~]# docker tag 5e5949f1bda7 harbor.od.com/public/blackbox-exporter:v0.16.0
[root@ops-200 ~]# docker push harbor.od.com/public/blackbox-exporter:v0.16.0

准备资源配置清单

创建资源目录

1
2
[root@ops-200 ~]# mkdir /data/k8s-yaml/blackbox-exporter
[root@ops-200 ~]# cd /data/k8s-yaml/blackbox-exporter

编写yaml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
[root@ops-200 blackbox-exporter]# vim configmap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
labels:
app: blackbox-exporter
name: blackbox-exporter
namespace: kube-system
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

[root@ops-200 blackbox-exporter]# vim deployment.yaml
kind: Deployment
apiVersion: apps/v1
metadata:
name: blackbox-exporter
namespace: kube-system
labels:
app: blackbox-exporter
annotations:
deployment.kubernetes.io/revision: 1
spec:
replicas: 1
selector:
matchLabels:
app: blackbox-exporter
template:
metadata:
labels:
app: blackbox-exporter
spec:
volumes:
- name: config
configMap:
name: blackbox-exporter
defaultMode: 420
containers:
- name: blackbox-exporter
image: harbor.od.com/public/blackbox-exporter:v0.16.0
imagePullPolicy: IfNotPresent
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

[root@ops-200 blackbox-exporter]# vim service.yaml
kind: Service
apiVersion: v1
metadata:
name: blackbox-exporter
namespace: kube-system
spec:
selector:
app: blackbox-exporter
ports:
- name: blackbox-port
protocol: TCP
port: 9115

[root@ops-200 blackbox-exporter]# vim ingress.yaml
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: blackbox-exporter
namespace: kube-system
spec:
rules:
- host: blackbox.od.com
http:
paths:
- path: /
backend:
serviceName: blackbox-exporter
servicePort: blackbox-port

应用资源配置清单

1
2
3
4
5
6
7
8
9
[root@ops-200 blackbox-exporter]# kubectl apply -f configmap.yaml 
configmap/blackbox-exporter created
[root@ops-200 blackbox-exporter]# kubectl apply -f deployment.yaml
deployment.apps/blackbox-exporter created
[root@ops-200 blackbox-exporter]# kubectl apply -f service.yaml
service/blackbox-exporter created
[root@ops-200 blackbox-exporter]# kubectl apply -f ingress.yaml
ingress.extensions/blackbox-exporter created

查看数据

image-20200413113442498