一、前言
? ? ? 部署在k8s中需要用到deployment、configmap、service服务
二、部署
? ? ?创建存放yaml的目录
? ? ?mkdir?/opt/blackbox-exporter &&? cd?/opt/blackbox-exporter
? ? ?编辑blackbox配置文件,使用configmap挂在这
? ? ?vi configmap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: blackbox-exporter
namespace: monitor
labels:
app: blackbox-exporter
data:
blackbox.yml: |-
modules:
http_2xx:
prober: http
http:
valid_status_codes: [200,204]
no_follow_redirects: false
preferred_ip_protocol: ip4
ip_protocol_fallback: false
httpNoRedirect4ssl:
prober: http
http:
valid_status_codes: [200,204,301,302,303]
no_follow_redirects: true
preferred_ip_protocol: ip4
ip_protocol_fallback: false
http200igssl:
prober: http
http:
valid_status_codes:
- 200
tls_config:
insecure_skip_verify: true
http_4xx:
prober: http
http:
valid_status_codes: [401,403,404]
preferred_ip_protocol: ip4
ip_protocol_fallback: false
http_5xx:
prober: http
http:
valid_status_codes: [500,502]
preferred_ip_protocol: ip4
ip_protocol_fallback: false
http_post_2xx:
prober: http
http:
method: POST
icmp:
prober: icmp
tcp_connect:
prober: tcp
ssh_banner:
prober: tcp
tcp:
query_response:
- expect: "^SSH-2.0-"
- send: "SSH-2.0-blackbox-ssh-check"
? ? ?编辑deployment服务的yaml
? ? ?vi deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: blackbox-exporter
namespace: monitor
spec:
replicas: 1
selector:
matchLabels:
app: blackbox-exporter
template:
metadata:
labels:
app: blackbox-exporter
spec:
containers:
- name: blackbox-exporter
image: prom/blackbox-exporter:latest
imagePullPolicy: IfNotPresent
ports:
- containerPort: 9115
readinessProbe:
tcpSocket:
port: 9115
initialDelaySeconds: 10
timeoutSeconds: 5
resources:
requests:
memory: 50Mi
cpu: 100m
limits:
memory: 60Mi
cpu: 200m
volumeMounts:
- name: config
mountPath: /etc/blackbox_exporter
args:
- '--config.file=/etc/blackbox_exporter/blackbox.yml'
- '--web.listen-address=:9115'
volumes:
- name: config
configMap:
name: blackbox-exporter
编辑service服务的yaml
? ? ?vi service.yaml
apiVersion: v1
kind: Service
metadata:
labels:
name: blackbox-exporter
name: blackbox-exporter
namespace: monitor
spec:
ports:
- name: blackbox-exporter
protocol: TCP
port: 9115
targetPort: 9115
selector:
app: blackbox-exporter
创建命名空间
kubectl create namespace monitor
创建yaml文件对应服务
kubectl apply -f?configmap.yaml
kubectl apply -f?deployment.yaml
kubectl apply -f service.yaml
查看服务是否正常
kubectl get pod -n monitor
至此blackbox-exporter部署完成?