一、前言
在k8s内部署mysql-exporter监控需要用到deployment、service服务
二、部署
在被监控的mysql中创建监控用户
mysql -u root -p
GRANT PROCESS, REPLICATION CLIENT ON *.* TO 'monitor@'%' identified by '12345678';
flush privileges;
创建mysql-exporter服务的yaml文件存放目录
mkdir /opt/mysql-exporter && cd /opt/mysql-exporter
编辑deployment的yaml文件
vi deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:name: mysqld-exporternamespace: monitorlabels:app: mysqld-exporter
spec:selector:matchLabels:app: mysqld-exportertemplate:metadata:labels:app: mysqld-exporterspec:containers:- name: mysqld-exporterimage: swr.cn-south-1.myhuaweicloud.com/starsl.cn/mysqld_exporter:latestcommand:- /bin/mysqld_exporter- --collect.info_schema.innodb_metrics- --collect.info_schema.tables- --collect.info_schema.processlist- --collect.info_schema.tables.databases=*- --mysqld.username=monitor #监控用户名称env:- name: MYSQLD_EXPORTER_PASSWORDvalue: 12345678 #监控用户密码ports:- containerPort: 9104name: httpvolumeMounts:- mountPath: /etc/localtime name: tz-configvolumes:- name: tz-config #挂载时间配置,与宿主机配置时间同步hostPath:path: /usr/share/zoneinfo/Asia/Shanghai
编辑service的yaml文件
vi service.yaml
apiVersion: v1
kind: Service
metadata:labels:app: mysqld-exportername: mysqld-exporternamespace: monitor
spec:type: NodePortports:- name: httpport: 9104targetPort: 9104nodePort: 30010selector:app: mysqld-exporter
执行创建yaml文件对应的服务
kubectl apply -f deployment.yaml
kubectl apply -f service.yaml
查看部署是否正常
kubectl get pod -n monitor