部署 MySQL-exporter
注意需要给MySQL 创建用户使其能够查询数据库
CREATE USER 'exporter'@'%' IDENTIFIED BY 'XXXXXXXX';
GRANT PROCESS, REPLICATION CLIENT ON *.* TO 'exporter'@'%';
GRANT SELECT ON performance_schema.* TO 'exporter'@'%'
mysql exporter 依赖于my.cnf 配置文件,所以需要添加一个 configmap
---
apiVersion: v1
kind: ConfigMap
metadata:
name: mysqld-exporter-config
namespace: monitoring
data:
my.cnf: |
[client]
host=10.0.1.2
port=3306
user=exporter
password=xxxxx
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: mysqld-exporter
namespace: monitoring
labels:
app: mysqld-exporter
spec:
selector:
matchLabels:
app: mysqld-exporter
template:
metadata:
labels:
app: mysqld-exporter
spec:
containers:
- name: mysqld-exporter
image: prom/mysqld-exporter
ports:
- containerPort: 9104
name: http
volumeMounts:
- name: mysqld-config-volume
mountPath: /.my.cnf
subPath: my.cnf
volumes:
- name: mysqld-config-volume
configMap:
name: mysqld-exporter-config
---
apiVersion: v1
kind: Service
metadata:
name: mysqld-exporter
namespace: monitoring
labels:
app: mysqld-exporter
spec:
ports:
- name: api
port: 9104
targetPort: 9104
type: ClusterIP
selector:
app: mysqld-exporter
---
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
labels:
app.kubernetes.io/name: mysqld-exporter
app.kubernetes.io/part-of: kube-prometheus
name: mysqld-exporter
namespace: monitoring
spec:
endpoints:
- honorLabels: true
interval: 30s
path: /metrics
port: api
scheme: http
namespaceSelector:
matchNames:
- monitoring
selector:
matchLabels:
app: mysqld-exporter