一、前言
部署在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-exporternamespace: monitorlabels:app: blackbox-exporter
data:blackbox.yml: |-modules:http_2xx:prober: httphttp:valid_status_codes: [200,204]no_follow_redirects: falsepreferred_ip_protocol: ip4ip_protocol_fallback: falsehttpNoRedirect4ssl:prober: httphttp:valid_status_codes: [200,204,301,302,303]no_follow_redirects: truepreferred_ip_protocol: ip4ip_protocol_fallback: falsehttp200igssl:prober: httphttp:valid_status_codes:- 200tls_config:insecure_skip_verify: truehttp_4xx:prober: httphttp:valid_status_codes: [401,403,404]preferred_ip_protocol: ip4ip_protocol_fallback: falsehttp_5xx:prober: httphttp:valid_status_codes: [500,502]preferred_ip_protocol: ip4ip_protocol_fallback: falsehttp_post_2xx:prober: httphttp:method: POSTicmp:prober: icmptcp_connect:prober: tcpssh_banner:prober: tcptcp: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-exporternamespace: monitor
spec:replicas: 1selector:matchLabels:app: blackbox-exportertemplate:metadata:labels:app: blackbox-exporterspec:containers:- name: blackbox-exporterimage: prom/blackbox-exporter:latestimagePullPolicy: IfNotPresentports:- containerPort: 9115readinessProbe:tcpSocket:port: 9115initialDelaySeconds: 10timeoutSeconds: 5resources:requests:memory: 50Micpu: 100mlimits:memory: 60Micpu: 200mvolumeMounts:- name: configmountPath: /etc/blackbox_exporterargs:- '--config.file=/etc/blackbox_exporter/blackbox.yml'- '--web.listen-address=:9115'volumes:- name: configconfigMap:name: blackbox-exporter
编辑service服务的yaml
vi service.yaml
apiVersion: v1
kind: Service
metadata:labels:name: blackbox-exportername: blackbox-exporternamespace: monitor
spec:ports:- name: blackbox-exporterprotocol: TCPport: 9115targetPort: 9115selector: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部署完成