一、前言
? ? ?在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-exporter
namespace: monitor
labels:
app: mysqld-exporter
spec:
selector:
matchLabels:
app: mysqld-exporter
template:
metadata:
labels:
app: mysqld-exporter
spec:
containers:
- name: mysqld-exporter
image: swr.cn-south-1.myhuaweicloud.com/starsl.cn/mysqld_exporter:latest
command:
- /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_PASSWORD
value: 12345678 #监控用户密码
ports:
- containerPort: 9104
name: http
volumeMounts:
- mountPath: /etc/localtime
name: tz-config
volumes:
- name: tz-config #挂载时间配置,与宿主机配置时间同步
hostPath:
path: /usr/share/zoneinfo/Asia/Shanghai
?编辑service的yaml文件
?vi service.yaml
apiVersion: v1
kind: Service
metadata:
labels:
app: mysqld-exporter
name: mysqld-exporter
namespace: monitor
spec:
type: NodePort
ports:
- name: http
port: 9104
targetPort: 9104
nodePort: 30010
selector:
app: mysqld-exporter
?执行创建yaml文件对应的服务
? kubectl apply -f deployment.yaml
kubectl apply -f service.yaml
查看部署是否正常
kubectl get pod -n monitor