在此前的文档里面具体描述了通过operator部署Prometheus,这篇文章具体探讨一下operator的一些修改从而实现自定义。下面的链接是Prometheus-operator的部署。
https://zhuchance.github.io/post/prometheusoperator%E9%83%A8%E7%BD%B2/
这里要实现Prometheus把采集的数据往另一个地方推送
-
下载 kube-prometheus-0.6.0注意这个版本要和k8s版本匹配 ,地址:https://github.com/prometheus-operator/kube-prometheus/archive/v0.6.0.tar.gz
-
自定义配置:主要是修改alertmanager-main推送,这里遇到一个坑很久,operator里面的配置是加密后压缩的乱码,尝试用过解密修改后再写入结果发现还是不能达到修改的目的,又查阅了资料发现是在prometheus-prometheus.yaml这里面修改才生效的。
通过这种方式能看到配置信息但其实任然无法修改 https://my.oschina.net/neverforget/blog/4816486
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
apiVersion: monitoring.coreos.com/v1
kind: Prometheus
metadata:
labels:
prometheus: k8s
name: k8s
namespace: monitoring
spec:
alerting:
alertmanagers:
- name: alertmanager-main
namespace: monitoring
port: web
remoteWrite:
- url: http://remoteip:port/insert/24:24/prometheus
queueConfig:
maxSamplesPerSend: 10000
image: quay.io/prometheus/prometheus:v2.20.0
nodeSelector:
kubernetes.io/os: linux
podMonitorNamespaceSelector: {}
podMonitorSelector: {}
replicas: 1
resources:
requests:
memory: 4000Mi
ruleSelector:
matchLabels:
prometheus: k8s
role: alert-rules
securityContext:
fsGroup: 2000
runAsNonRoot: true
runAsUser: 1000
serviceAccountName: prometheus-k8s
serviceMonitorNamespaceSelector: {}
serviceMonitorSelector: {}
version: v2.20.0
|
- 自定义告警邮箱类型:添加alernabager
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
apiVersion: v1
data: {}
kind: Secret
metadata:
name: alertmanager-main
namespace: monitoring
stringData:
alertmanager.yaml: |
global:
resolve_timeout: 5m
smtp_smarthost: 'smtp.qq.com:465'
smtp_from: '123456701@qq.com'
smtp_auth_username: '123456701@qq.com'
smtp_auth_password: 'sdjlkjseu739cxnh' #账户密码已做脱敏无需担心
smtp_hello: '警报邮件'
smtp_require_tls: false
route:
group_by: ['alertname', 'cluster']
group_wait: 30s
group_interval: 30s
repeat_interval: 12h
receiver: default
routes:
- receiver: email
group_wait: 10s
match:
team: ops
receivers:
- name: 'default'
email_configs:
#- to: '1234567890@189.cn'
- to: 'sendemail@123.com'
send_resolved: true
- name: 'email'
email_configs:
- to: 'sendemail@123.com'
send_resolved: true
type: Opaque
|