Kube-Prometheus监控MySQL(二)
MySQL
Deployment
apiVersion: apps/v1
kind: Deployment
metadata:
#设置唯一名称,建议添加数据库实例ip
name: mysql-exporter-172.16.1.77
namespace: monitoring
labels:
app.kubernetes.io/component: exporter
app.kubernetes.io/name: mysql-exporter
app.kubernetes.io/part-of: kube-prometheus
app.kubernetes.io/version: v0.14.0
spec:
selector:
matchLabels:
app.kubernetes.io/component: exporter
app.kubernetes.io/name: mysql-exporter
app.kubernetes.io/part-of: kube-prometheus
replicas: 1
template:
metadata:
labels:
app.kubernetes.io/component: exporter
app.kubernetes.io/name: mysql-exporter
app.kubernetes.io/part-of: kube-prometheus
app.kubernetes.io/version: v0.14.0
spec:
containers:
- name: mysql-exporter
image: prom/mysqld-exporter:v0.14.0
env:
- name: DATA_SOURCE_NAME
# 修改真实的数据库用户名和密码信息 以及地址信息
# 格式为:用户名:密码@(数据库的域名或者ip:端口)/
value: "root:password@(mysql-service.share-components:3306)/"
resources:
requests:
cpu: 20m
memory: 20Mi
limits:
cpu: 100m
memory: 30Mi
ports:
- containerPort: 9104
name: http
volumeMounts:
- name: localtime
mountPath: /etc/localtime
volumes:
- name: localtime
hostPath:
path: /usr/share/zoneinfo/Asia/Shanghai
restartPolicy: Always
Service
apiVersion: v1
kind: Service
metadata:
name: mysql-exporter
namespace: monitoring
labels:
app.kubernetes.io/component: exporter
app.kubernetes.io/name: mysql-exporter
app.kubernetes.io/part-of: kube-prometheus
app.kubernetes.io/version: v0.14.0
platform: mos
spec:
selector:
app.kubernetes.io/component: exporter
app.kubernetes.io/name: mysql-exporter
app.kubernetes.io/part-of: kube-prometheus
type: ClusterIP
ports:
- name: http
port: 9104
targetPort: http
ServiceMonitor
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
labels:
app.kubernetes.io/component: exporter
app.kubernetes.io/name: mysql-exporter
app.kubernetes.io/part-of: kube-prometheus
app.kubernetes.io/version: v0.14.0
name: mysql-exporter
namespace: monitoring
spec:
endpoints:
- interval: 15s
port: http
relabelings:
- action: replace
regex: (.*)
replacement: $1
sourceLabels:
- __meta_kubernetes_pod_node_name
targetLabel: instance
scheme: http
jobLabel: app.kubernetes.io/name
targetLabels: [platform]
selector:
matchLabels:
app.kubernetes.io/component: exporter
app.kubernetes.io/name: mysql-exporter
app.kubernetes.io/part-of: kube-prometheus
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 逐光の博客!
评论