赞
踩
1、安装mysql服务
kubectl create deploy mysql --image=registry.cn-beijing.aliyuncs.com/dotbalo/mysql:5.7.23
1.1、使用变量设置mysql密码
kubectl set env deploy/mysql MYSQL_ROOT_PASSWORD=mysql
1.2、暴露mysql端口
kubectl expose deploy mysql --port 3306
1.3、授权mysql账户
CREATE USER 'exporter'@'%' IDENTIFIED BY 'exporter' WITH MAX_USER_CONNECTIONS 3;
Query OK, 0 rows affected (0.01 sec)
GRANT PROCESS, REPLICATION CLIENT, SELECT ON *.* TO 'exporter'@'%';
Query OK, 0 rows affected (0.00 sec)
2、创建mysql-exporter服务
[root@master ~]# cat mysql-exporter.yaml apiVersion: apps/v1 kind: Deployment metadata: name: mysql-exporter namespace: kuboard spec: replicas: 1 selector: matchLabels: k8s-app: mysql-exporter template: metadata: labels: k8s-app: mysql-exporter spec: containers: - name: mysql-exporter image: registry.cn-beijing.aliyuncs.com/dotbalo/mysqld-exporter env: - name: DATA_SOURCE_NAME value: "root:123456@(192.168.122.222:30295)/" # 要监控的mysql账号信息 imagePullPolicy: IfNotPresent ports: - containerPort: 9104 --- apiVersion: v1 kind: Service metadata: name: mysql-exporter namespace: kuboard labels: k8s-app: mysql-exporter spec: type: ClusterIP selector: k8s-app: mysql-exporter ports: - name: api port: 9104 protocol: TCP
2.1、部署mysql-exporter
kubectl apply -f mysql-exporter.yaml
2.2、验证是否部署成功
[root@master ~]# kubectl get pod,svc -n kuboard
mysql-exporter-7cff6b6759-q7djh 1/1 Running 0 17h
mysql-exporter ClusterIP 10.108.108.48 <none> 9104/TCP 17h
2.3、查看 ENDPOINTS
[root@master ~]# kubectl get ep -n kuboard
mysql-exporter 10.244.1.93:9104 17h
2.4、部署servicemonitor
[root@master ~]# cat mysql-sm.yanl apiVersion: monitoring.coreos.com/v1 kind: ServiceMonitor metadata: labels: k8s-app: mysql-exporter name: mysql-exporter namespace: kuboard spec: endpoints: - interval: 15s port: api scheme: http selector: matchLabels: k8s-app: mysql-exporter namespaceSelector: matchNames: - kuboard
2.4.1、查看 servicemonitor是否部署成功
[root@master ~]# kubectl get servicemonitor -n kuboard
NAME AGE
mysql-exporter 17h
3、prometheus 界面查看
4、granfana 图形化展示(导入6239模板)
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。